◢◤ ARKANE_
SYS_TIME UTC+0
Work with me
/W09

实验Lab: Forests and boosting

week 9
Dataset
California housing (20,640 districts, 1990 US Census)
Time
3 hours

This week you'll be able to

  • Explain why bagging lowers variance and boosting lowers bias.
  • Train and tune a random forest and a gradient-boosted model, and compare them with a single tree.
  • Read feature importances and say what they do and do not show.

Goal

Beat a single tree with bagging and boosting on a regression problem. Tune them properly and read what their importances do and don't show.

Data

The dataset you explored in week 7. Reuse your notes on the capped values.

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split

X, y = fetch_california_housing(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Tasks

  1. Fit a linear regression and a single decision tree. Report test RMSE for both. These are your baselines.
  2. Fit a random forest. Tune n_estimators and max_depth (Procedure 12.1). Plot validation RMSE against the number of trees. Where does it level off?
  3. Fit a gradient-boosted model: HistGradientBoostingRegressor, XGBoost, or LightGBM. Use early stopping on a validation split.
  4. Compare all four models in one table: test RMSE, training time, and prediction time. Use Procedure 12.3 to say which you'd ship.
  5. Plot feature importance for the forest (Procedure 12.2). Then compute permutation importance on the test set. Where do they disagree, and why?
  6. Look at the 20 largest errors of your best model. How many are capped districts?

Deliverable

A notebook with the comparison table, both importance plots, and a paragraph on task 6.

Done when

  • Every ensemble beats the single tree on test RMSE.
  • Early stopping is on a validation split, not the test set.
  • The importance comparison says what each method measures.

Stretch

Build a stacking ensemble from the forest, the boosted model, and a ridge regression (Procedure 12.4). Does it beat the best single model by enough to justify it?

online /teaching/semester-1/labs/9 Newcastle, UK v0.1.0 // rss