Solution (source code)

= Solution

A <regression tree> chooses a threshold $s$ and constant predictions $c_L,c_R$ to minimize the squared-error criterion
$$
\min_{s,c_L,c_R}
\left\{
\sum_{i:X_i\leq s}(Y_i-c_L)^2
+\sum_{i:X_i>s}(Y_i-c_R)^2
\right\},
$$
where $s$ ranges over thresholds producing two nonempty groups. For a fixed split, the <ordinary least squares estimators>[least-squares] minimizers are the two sample means,
$$
c_L=\frac{1}{n_L}\sum_{X_i\leq s}Y_i,
\qquad
c_R=\frac{1}{n_R}\sum_{X_i>s}Y_i.
$$
\b[Thus the first split is the candidate threshold with the smallest sum of the two within-node residual sums of squares.]