PIXELBANKv8.2.1
Menu

Gradient Boosting Residual Step

Implement one step of Gradient Boosting for regression.

Given current predictions y^\hat{y} and true values yy:

  1. Compute residuals: ri=yiy^ir_i = y_i - \hat{y}_i
  2. 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 (\leq threshold) and right (>> threshold) groups.
  3. Update predictions: y^i=y^i+ηh(xi)\hat{y}_i' = \hat{y}_i + \eta \cdot h(x_i) where η\eta is the learning rate and h(xi)h(x_i) 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=yiy^ir_i = y_i - \hat{y}_i which results in r=[32,65,43,87]=[1,1,1,1]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 (\leq 2.5) is (1+1)/2=1(1+1)/2 = 1 and for the right group (>> 2.5) is (1+1)/2=1(1+1)/2 = 1.
  • Update predictions: y^i=y^i+ηh(xi)\hat{y}_i' = \hat{y}_i + \eta \cdot h(x_i) where η=0.1\eta = 0.1 and h(xi)h(x_i) is the predicted residual, which is 1 for all samples, resulting in y^i=y^i+0.11=y^i+0.1\hat{y}_i' = \hat{y}_i + 0.1 \cdot 1 = \hat{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][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

Test Results

0/0
Run code to see test results.