All problems
Gradient Boosting Stump
Problem
Fit a depth-1 regression stump to gradients (residuals). For each threshold midway between consecutive unique feature values, split X into left (x <= t) and right (x > t) and predict each side's mean gradient.
Return [threshold, left_mean, right_mean] for the split with the lowest total squared error; if no split exists, return [0.0, mean, mean]. Empty input returns [0.0, 0.0, 0.0].
Hint
A stump predicts the mean gradient in each leaf; the best threshold minimizes the total squared error.
Test cases
case 1
in: [[1,2,3,4],[1,1,-1,-1]]
expected: [2.5,1,-1]
case 2
in: [[1,2,3],[3,1,2]]
expected: [1.5,3,1.5]
case 3
in: [[1,1,2,3],[1,3,2,4]]
expected: [2.5,2,4]
case 4
in: [[5],[2]]
expected: [0,2,2]
case 5
in: [[],[]]
expected: [0,0,0]
Starter codePython
def gradient_boosting_stump(X, gradients):
# Returns [threshold, left_mean, right_mean]
# Your code here
pass5 test cases · run your code against them in the editor