Learning Rate Sweep with Early Stopping for HistGradientBoostingRegressor
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Implement `run_learning_rate_experiment(X, y, learning_rates, max_iter=200, validation_fraction=0.2, n_iter_no_change=5, random_state=0)`. For each learning rate, fit a scikit-learn `HistGradientBoostingRegressor` with early stopping on a held-out validation fraction, and return a `pandas.DataFrame` that summarizes the run with one row per learning rate.
Requirements:
- Fit with `early_stopping=True` and `scoring="loss"`, and forward `max_iter`, `validation_fraction`, `n_iter_no_change` and `random_state`.
- The columns are exactly `["learning_rate", "n_iter", "best_val_score"]`, with dtypes `float64`, `int64` and `float64`.
- `n_iter` is the fitted model's `n_iter_`, which equals `max_iter` if early stopping never triggers.
- `best_val_score` is `max(validation_score_)`. It is a negative loss, so it is always `<= 0`.
- Rows follow the input order of `learning_rates`.
Sample output on a regression dataset (the numbers depend on the data):
```python
run_learning_rate_experiment(X, y, [0.05, 0.2, 0.8], max_iter=150)
# learning_rate n_iter best_val_score
# 0 0.05 ... -0.0...
# 1 0.20 ... -0.0...
# 2 0.80 ... -0.0...
```
```hint Defaults and sign conventions
Check what the default `early_stopping="auto"` does on a small dataset, and which sign scikit-learn uses for the entries of `validation_score_` when `scoring="loss"`.
```
### What a Strong Answer Covers
- Forcing early stopping on and forwarding every parameter, so that all learning rates are compared on the same validation split.
- Reading `n_iter_` and the maximum of `validation_score_`, with the sign convention explained.
- A DataFrame with the exact column order and dtypes, rows in input order, and sensible behavior for an empty list of rates.
- How `n_iter_` relates to the best iteration, and what the sweep shows about the trade-off between learning rate and number of trees.
### Follow-up Questions
- Why do smaller learning rates usually need more iterations?
- How would you reproduce this in XGBoost?
- Is a single validation split reliable for picking the learning rate?
Overview: Write a scikit-learn experiment that fits a histogram gradient boosting regressor with early stopping for several learning rates and returns a typed pandas summary. Tests early stopping settings, how validation scores are reported, and the trade-off between learning rate and number of trees.