Regression trees
Quick answer
Regression trees predict a numerical target instead of a class. With squared-error loss, a leaf predicts the mean of its training targets and a split seeks to reduce squared residuals. Examples run locally with Python 3.13.5, scikit-learn 1.8.0, NumPy 2.3.5 and SciPy 1.17.0 when imported. ByteMind library execution is unverified.
Compute the SSE reduction
def sse(y): m=sum(y)/len(y) return sum((v-m)**2 for v in y)l=[2,4]; r=[10,12]print(sse(l+r),sse(l)+sse(r),sse(l+r)-sse(l)-sse(r))Expected output:
68.0 4.0 64.0The split removes most between-group variation while each child retains small residuals.
How it works
For targets y_1 through y_n, the mean minimizes sum((y_i−a)²) over constant predictions a. This follows by setting the derivative to zero. A parent with targets [2,4,10,12] has mean 7 and SSE 68. Splitting into [2,4] and [10,12] yields means 3 and 11 and SSE 2+2=4, a decrease of 64. Dividing SSE by the number of parent rows produces the corresponding decrease in mean squared error, 16. The split is chosen by minimizing weighted child impurity, equivalent here to minimizing child SSE. In DecisionTreeRegressor criterion=squared_error uses mean leaves; absolute_error uses median leaves, which can resist extreme target values. The poisson criterion applies to nonnegative targets and requires a positive total target; use it only for suitable count-like data. A fitted tree is piecewise constant and generally cannot extrapolate a rising trend outside its training range. Unlike classification Gini, regression squared error carries squared target units. For weighted training, means and impurity are weighted. Inspect held-out residuals and compare to a train-only constant baseline.
See piecewise constant predictions
from sklearn.tree import DecisionTreeRegressorm=DecisionTreeRegressor(max_depth=1,random_state=7).fit([[1],[2],[5],[6]],[2,4,10,12])print(m.predict([[0],[2],[4],[20]]).tolist())Expected output:
[3.0, 3.0, 11.0, 11.0]The extreme input 20 still receives the right leaf mean, not an extrapolated trend.
Common mistakes
Do not use classification impurity on continuous targets. Do not interpret a mean leaf as a prediction interval. Median and mean leaves optimize different objectives.
Practice and next steps
Compute the mean and median for [1,2,20]. Compare total squared error and total absolute error for each candidate. Complete the knowledge check and coding exercise. Next: Depth and leaf constraints.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Regression trees — knowledge check
Apply regression trees to new examples.
Squared-error leaf prediction for [2,4,9]?
SSE for targets [2,4] predicted by 3?
Which criterion uses median leaves?
What happens far beyond the largest trained feature value?
Which data should define a constant baseline?