📘
Gradient Boosting Residual Step
HardEnsemble Methods
Implement one step of Gradient Boosting for regression.
Given current predictions y^ and true values y:
- Compute residuals: ri=yi−y^i
- Fit a simple model to the residuals: compute the mean residual for each group defined by a feature threshold. Given the split threshold, predict the mean residual for left (≤ threshold) and right (> threshold) groups.
- Update predictions: y^i′=y^i+η⋅h(xi) where η is the learning rate and h(xi) is the predicted residual.
Return the updated predictions, rounded to 4 decimal places.
Example:
Input:
y_true = [3, 6, 4, 8] y_pred = [2, 5, 3, 7] feature_values = [1, 3, 2, 4] threshold = 2.5 learning_rate = 0.1
Output:
[2.1, 5.1, 3.1, 7.1]
Reasoning:
- Compute residuals: ri=yi−y^i which results in r=[3−2,6−5,4−3,8−7]=[1,1,1,1]
- Fit a simple model to the residuals: since the feature threshold is 2.5, the mean residual for the left group (≤ 2.5) is (1+1)/2=1 and for the right group (> 2.5) is (1+1)/2=1.
- Update predictions: y^i′=y^i+η⋅h(xi) where η=0.1 and h(xi) is the predicted residual, which is 1 for all samples, resulting in y^i′=y^i+0.1⋅1=y^i+0.1
- The final output is obtained by applying the update to each prediction and rounding to 4 decimal places: [2+0.1,5+0.1,3+0.1,7+0.1]=[2.1,5.1,3.1,7.1]
Constraints:
- y_true, y_pred: lists of actual and current predicted values
- feature_values: list of feature values for splitting
- threshold: split value
- learning_rate: float > 0
- Return list of updated predictions rounded to 4 decimal places
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.