MACHINE LEARNING / 5. GRADIENT BOOSTING & XGBOOST
Gradient Boosting & XGBoost
The best model on tabular data — period
EXPLANATION
Gradient Boosting builds trees sequentially, where each new tree corrects the errors of all previous trees. It literally trains on the residuals. Algorithm: 1. Start with a simple prediction (mean of y) 2. Compute residuals = y - ŷ 3. Fit a new tree to predict the residuals 4. Update: ŷ = ŷ + lr * new_tree(X) 5. Repeat N times XGBoost improvements over vanilla GBM: • Regularization (L1/L2 on leaf weights) → prevents overfitting • Second-order gradients (Newton boosting) → better optimization • Column/row subsampling → like random forest, adds variance reduction • Parallel tree building → much faster • Handles missing values natively LightGBM is even faster — uses histogram-based splits and grows trees leaf-wise rather than level-wise. In practice: XGBoost/LightGBM win every Kaggle tabular competition. If you're on structured data, try these before anything else.
DATA FLOW
Iteration 1: predict mean(y). Residuals = y - mean(y)
↓
Tree 1: fits residuals → small corrections
↓
ŷ = mean(y) + lr × Tree1(X)
↓
New residuals = y - ŷ
↓
Tree 2: fits new residuals → more corrections
↓
ŷ = mean(y) + lr×Tree1 + lr×Tree2
↓
... repeat N times ...
↓
Final: ŷ = Σ lr × Treeᵢ(X) ← ensemble of weak learnersCODE