#248Gradient Boosting: One Round (Stump)MediumDecision TreesEnsemble LearningBoostingAsked atMicrosoft · Meta · Amazon
Gradient Boosting: One Round (Stump)
Background
Gradient Boosting fits a sequence of weak learners on the pseudo-residuals of the running prediction. For mean-squared-error regression, the pseudo-residual is simply — fit a stump to the residuals, scale by the learning rate, add to . One round.
Problem statement
Implement gbm_one_round(X, y, F, lr=0.1) for regression. Steps:
- Compute residuals .
- Find the best single-threshold split on
X[:, 0](the only feature) that minimises the sum of squared residuals across the two halves. - For each side, predict the mean of
ron that side. - Update .
Input
X—np.ndarrayshape , single-feature input matrix.y— 1-D array of length , target.F— 1-D array of length , current model output.lr—float, learning rate (default0.1).
Output
Returns np.ndarray of length , the new .
Examples
Example 1 — reduces MSE on a separable problem
Input: X = bimodal feature, y = signs of X, F = zeros
Output: MSE(F_new) < MSE(F)
Example 2 — lr = 0 leaves F unchanged
Input: any X, y, F
Output: F_new = F
Constraints
- has shape .
- Try every unique value in
X[:, 0]as a candidate threshold; pick the one minimising squared residual. - Returns
np.ndarrayof length .
Notes
- Why stumps. Depth-1 trees are the simplest possible weak learner; gradient boosting compensates for their weakness with many rounds.
- Multi-feature extension. Production GBMs sweep all features, picking the best
(feature, threshold)pair per round. This kernel isolates the per-feature mechanic.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: three-point single-threshold split
- •Sample: two-point split predicts exact values
- •Sample: four points, threshold-split step