Learning Curves and Plateau Detection
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Implement `learning_curve_mse(estimator, X, y, splits, train_sizes)`, which computes mean train and validation MSE per training size over fixed `(train_idx, val_idx)` splits. Then implement `detect_plateau(train_sizes, val_mse, rel_tol=0.01)`, which finds where validation error stops improving.
Requirements:
- For each size `n` and split, fit a fresh `clone` on `train_idx[:n]`. Train MSE uses those `n` points, and validation MSE uses all of `val_idx`. Never fit `estimator` in place.
- Return a dict with `train_sizes` (int array), `train_mse` and `val_mse` (means over splits), and `val_std` (std over splits, `ddof=0`). An empty `splits` list, or any `n` outside `[1, len(train_idx)]`, raises `ValueError`.
- The step improvement is `(val[i-1] - val[i]) / val[i-1]`, or `0.0` when `val[i-1] == 0`.
- `plateau_size` is the first `train_sizes[i]` (with `i >= 1`) whose improvement is strictly below `rel_tol`, or `None` if there is none. `more_data_helps` is true when the last step's improvement is `>= rel_tol`.
- `detect_plateau` raises `ValueError` for fewer than 2 points or mismatched lengths.
Example:
```python
import numpy as np
from sklearn.dummy import DummyRegressor
X = np.arange(6.).reshape(-1, 1); y = [1, 3, 5, 7, 9, 11]
splits = [([0,1,2,3], [4,5]), ([2,3,4,5], [0,1])]
learning_curve_mse(DummyRegressor(), X, y, splits, [2, 4])
# train_mse=[1, 5], val_mse=[41, 37], val_std=[24, 0]
detect_plateau([10, 20, 40, 80], [10, 5, 4.9, 4.89], rel_tol=0.05)
# {'plateau_size': 40, 'more_data_helps': False}
```
```hint Validating sizes
Different splits can have different numbers of training indices, so think about where the size check has to run.
```
```hint When validation error goes up
Work out what the improvement formula returns when validation MSE rises from one size to the next, and whether that step should count as a plateau.
```
### Constraints & Assumptions
- `estimator` is a scikit-learn regressor. Do not use `sklearn.model_selection.learning_curve`.
- MSE values are finite and non-negative.
### What a Strong Answer Covers
- A fresh clone for every (size, split) pair, fitted on the prefix `train_idx[:n]`, with the caller's estimator left unfitted.
- Train MSE on the fitted points and validation MSE on the full validation set, averaged over splits, with `val_std` computed using `ddof=0`.
- The input checks in both functions.
- The plateau rule: relative step improvement, the zero-previous case, the strict comparison, a rising validation error, and `more_data_helps` from the last step.
### Follow-up Questions
- How would you use the curves to diagnose high bias versus high variance?
- Why is a single noisy dip a problem for plateau detection, and how would you make the detector less sensitive to split noise?
- What do nested prefixes of fixed training indices give you compared with resampling a fresh subset for each size?
Overview: Build learning curves by refitting cloned scikit-learn regressors on growing prefixes of fixed splits, then flag where validation MSE stops improving. It tests careful refitting, input validation and how to read train and validation curves for bias and variance.