Neural Mastery
← Practice
Gradient Boosting Pseudo-Residualseasy

Gradient Boosting Pseudo-Residuals

easy Classical ML from Scratch 10–15 min

NumPy allowed · plain Python earns 10 bonus points

Gradient descent step 1/4

Loss moves downhill

The update rule changes the parameters on each step.
Open lesson →
01parameters
02prediction
03loss
04gradient
θ = 4.000loss = 16.000∂L/∂θ = 8.000

θ ← θ − 0.14 · ∂L/∂θ

Compute negative gradient pseudo-residuals for regression and binary classification gradient boosting.

Related Skills

Task

Implement gbm_pseudo_residuals(y_true, raw_predictions, loss_type): for 'regression' (squared error), residual is y - raw. For 'classification' (binary log loss with y in {0, 1}), residual is y - sigmoid(raw). Return list of residuals rounded to 4 decimal places.

Function Signature

gbm_pseudo_residuals(y_true: list[float], raw_predictions: list[float], loss_type: str) -> list[float]

Examples

Example 1: Regression residuals
Input: y_true = [10, 5] raw_predictions = [8, 6] loss_type = 'regression'
Output: [2, -1]
Example 2: Binary classification zero logits gives 0.5 probs
Input: y_true = [1, 0] raw_predictions = [0, 0] loss_type = 'classification'
Output: [0.5, -0.5]

Constraints

  • len(y_true) == len(raw_predictions)
  • loss_type in ['regression', 'classification']
Python3Saved ✓
import math

def gbm_pseudo_residuals(y_true: list[float], raw_predictions: list[float], loss_type: str) -> list[float]:
"""Compute negative gradient direction (pseudo-residuals) for GBM.
loss_type is 'regression' or 'classification'.
Round floats to 4 decimal places.
"""
pass

Case 1: Regression residuals
Input: y_true = [10, 5] raw_predictions = [8, 6] loss_type = 'regression'
Expected: [2, -1]
Case 2: Binary classification zero logits gives 0.5 probs
Input: y_true = [1, 0] raw_predictions = [0, 0] loss_type = 'classification'
Expected: [0.5, -0.5]