Sub topic 11
From Diagnosis to Action
A learning curve or a validation curve tells you what is wrong with a model only if you turn the picture into a decision. This chapter covers that step. You read the gap between the training and validation scores, check where the validation curve is heading, and pick the remedy that fits.
This chapter assumes you can already compute both curves with learning_curve and validation_curve. It also assumes you know what underfitting, overfitting, bias, and variance mean, and that you are comfortable with scikit-learn estimators and pipelines.
Three Questions Before You Act
Every diagnosis starts from the same three observations, which you can read off a learning curve at its largest training size.
- Where is the validation score relative to your target? The target can be a business requirement, a baseline model, or a human-level score. Without it, "low" has no meaning.
- How big is the gap between training and validation scores? A large gap points to variance. A small gap with a low score points to bias.
- Is the validation curve still rising when the training size reaches its maximum? If it is, more data should help. If it has flattened, more data of the same kind will not.
The error bands from the previous chapter matter here. A gap of 0.02 is not a gap if the fold-to-fold standard deviation is 0.03.
Case 1: High Bias (Underfitting)
Signature. Training and validation scores are both below target and close together. The two curves flatten early, often after a small fraction of the data.
Why more data fails. The model cannot represent the pattern, so extra rows only give it more examples it cannot fit. The curves converge at the same mediocre level.
Remedies, in rough order of effort:
- Reduce regularization. Raise
CinLogisticRegressionorSVC, or loweralphainRidgeandLasso. - Use a more flexible model, such as a deeper tree, a larger
gammafor an RBF kernel, or a gradient-boosted ensemble instead of a linear model. - Add features that carry signal the model lacks, such as interaction terms, polynomial features, or domain-derived columns.
- Check the metric and the labels. If the labels are noisy, both curves will plateau low whatever the model does.
A validation curve confirms the diagnosis. If both scores rise together as complexity increases, you are on the underfitting side of the curve.
Case 2: High Variance (Overfitting)
Signature. The training score is high, often near perfect. The validation score is clearly lower, and the gap is larger than the fold-to-fold spread.
Here the second question decides the remedy.
- The validation curve is still rising. The gap is shrinking as data grows, so collecting more data is a sound choice. Estimate the benefit by extrapolating cautiously, and expect diminishing returns.
- The validation curve has flattened. More data will not close the gap. Reduce the model's capacity instead.
Capacity-reducing remedies:
- Increase regularization, such as a smaller
Cor a largeralpha. - Constrain the model with
max_depth,min_samples_leaf, or fewer hidden units. - Remove noisy or redundant features, or apply feature selection inside the cross-validation pipeline.
- Use averaging methods such as bagging or random forests, which lower variance without raising bias much.
- Stop iterative training earlier. Epoch curves are covered in a later chapter.
Case 3: The Curves Meet at a Good Score
If the curves converge and the validation score meets your target, the model is fine. Further tuning mostly fits noise in the validation folds. Stop, then confirm the result once on a held-out test set that you did not use for any of these decisions.
Case 4: Both Problems at Once
Real models can show a moderate gap and a validation score below target. The curves are neither close nor far apart. Treat this as a sequence, not a single decision. Fix bias first, because a model that cannot fit the training data gives you no useful information about variance. After you raise complexity, recompute the curves. If a large gap appears, move to variance remedies.
Reading a Validation Curve for Action
A validation curve answers a narrower question: which value of one hyperparameter balances bias and variance?
| Region of the curve | Training score | Validation score | Meaning | Action |
|---|---|---|---|---|
| Low complexity | Low | Low | High bias | Move toward more complexity |
| Near the peak | High | Highest | Good balance | Pick a value here |
| High complexity | Very high | Falling | High variance | Move back toward less complexity |
Pick a value at or just before the validation peak. If several values score within one standard deviation of the best, prefer the simplest. This is the "one standard error" rule, and it favors the model that is more likely to generalize and cheaper to run.
A Helper That Encodes the Heuristics
The following function turns the three questions into code. The thresholds are starting points, not laws. Adjust them to your metric and your tolerance.
import numpy as np
from sklearn.datasets import load_digits
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import learning_curve
def diagnose(model, X, y, target, cv=5, gap_tol=0.03, slope_tol=0.005):
sizes, train_scores, val_scores = learning_curve(
model,
X,
y,
train_sizes=np.linspace(0.2, 1.0, 5),
cv=cv,
scoring="accuracy",
)
train_mean = train_scores.mean(axis=1)
val_mean = val_scores.mean(axis=1)
val_std = val_scores.std(axis=1)
final_val = val_mean[-1]
gap = train_mean[-1] - final_val
slope = val_mean[-1] - val_mean[-2]
# A gap smaller than the fold spread is not evidence of variance.
significant_gap = gap > max(gap_tol, val_std[-1])
if final_val >= target:
return "Meets target: stop tuning and check on a held-out test set."
if not significant_gap:
return "High bias: add complexity or features, or reduce regularization."
if slope > slope_tol:
return "High variance, still improving: collect more data."
return "High variance, plateaued: simplify the model or add regularization."
X, y = load_digits(return_X_y=True)
print(diagnose(LogisticRegression(max_iter=2000), X, y, target=0.99))The helper compares the gap with the fold standard deviation, so a noisy curve does not trigger a variance diagnosis by accident. It also looks only at the last two points for the slope. On small datasets that slope is noisy, so always look at the plot before you trust the printed message.
Limits and Costs of Each Remedy
Diagnosis narrows the options, but each remedy has a price.
- More data is the slowest and most expensive fix. Estimate the gain from the slope before committing to collection or labeling.
- More complexity raises training time and the risk of swinging into overfitting. Make the change in small steps and recompute the curves each time.
- More regularization is cheap and reversible. Try it first when the diagnosis is variance, and use a validation curve over the regularization parameter to size it.
- Feature changes can fix bias and variance both, but they must live inside a pipeline so that every fold refits them. Otherwise the new scores are leaky and too optimistic.
Change one thing at a time. If you change the model, the features, and the regularization together, a new curve cannot tell you which change helped.
When the Score Cannot Improve
Sometimes both curves plateau at a score below target and no remedy helps. Common causes:
- Irreducible noise. The features do not contain enough information to predict the label better. No model fixes this, but better features or measurements can.
- Label errors. Inconsistent labels cap the achievable score.
- A mismatched metric. Accuracy on imbalanced classes can look flat while recall on the rare class is the real problem. Recompute the curves with a metric that matches the goal.
If the baseline or human-level score is also low, your target may simply be unrealistic. Compare against a simple baseline such as DummyClassifier before you spend effort on tuning.
Exercise
A learning curve shows a training accuracy of 0.99 and a validation accuracy of 0.82 at the full training size. The validation curve has been flat for the last three training sizes. The fold standard deviation is 0.01. Your target is 0.90. What do you diagnose, and what do you try first?
Show answer
The gap of 0.17 is far larger than the 0.01 fold spread, so this is high variance. The flat validation curve means more data of the same kind will not help. Try reducing capacity first: increase regularization, limit tree depth, or remove noisy features. Use a validation curve over the regularization hyperparameter to choose the new value, then recompute the learning curve.
Exercise
Both the training and validation accuracy are about 0.71 and the curves are within 0.01 of each other from 40% of the data onward. Your target is 0.85. A colleague suggests labeling 10,000 more rows. Is that a good plan, and what would you try instead?
Show answer
It is not a good plan. Close, flat curves at a low score indicate high bias, and more rows will not raise a model that cannot fit the pattern. Reduce regularization, use a more flexible model, or add informative features. Also check whether label noise or an unsuitable metric explains the plateau.