Diagnosing and tuning: is the number solid, would more data help, is there better?
Learning curve, cross-validation, validation curve and hyperparameter search, on twenty thousand California districts
Objectives
By the end of this session you will be able to:
- Read a learning curve and decide between more data and a different model
- Use cross-validation to say whether a single score means anything
- Vary one hyperparameter and find where overfitting starts
- Run a grid search and apply a combination without losing the previous model
- Use the Coach as a checklist, not as an oracle
- Read a model card and its computed limits
Prerequisites
- A rakoon-ds account on https://rakoon-ds.apps.way-up.io (free, browser only, nothing to install), and the group join code your instructor gives you
- A recent Chrome, Edge or Firefox. Computation runs either in your own tab (browser engine) or on the server; the header pill tells you which
- The mission for this session, assigned to your group. Open a project, then the Mission button in the workshop header: the panel opens next to Report. Click Check after each step
- Practical works 7 and 8 finished
- Patience: some of these computations take twenty seconds and the studio says so before starting
- Transformation, chart and algorithm names come from the rakoon-ds registry and are served in French even when the interface is in English. Every step below gives you the French label you will click and, in
code font, the registry key the mission checks against.
Data
The built-in california_housing dataset: 20 640 districts, 8 features, target price in hundreds of thousands of dollars, 1990 census.
One trap you must know before reading any curve: the target is truncated at 5.00001 and 965 districts sit on that ceiling. No model will ever predict above it, and the actual-against-predicted scatter shows a horizontal wall that no hyperparameter will remove. When a diagnostic says "the model cannot do better", check whether it is the model or the data.
Timing
The steps below add up to the announced duration. If you fall behind, Step 1 to Step 3 are the ones that must be finished.
| # | What you do | Time |
|---|---|---|
| Step 1 | A model worth diagnosing | 10 min |
| Step 2 | Learning curve: would more data help? | 15 min |
| Step 3 | Cross-validation: is the number solid? | 12 min |
| Step 4 | Validation curve: where overfitting starts | 13 min |
| Step 5 | Search, and apply without losing anything | 15 min |
| Step 6 | The Coach, and the model card | 10 min |
| Total | 75 min | |
Instructions
Step 1: A model worth diagnosing10 min
- New project
PW12 Diagnostics, add Prix immobilier Californie. - Train Modèle de référence (médiane) (
dummy_reg) onprice. Experiment labeldiagnostic. - Train Régression linéaire (
linreg). - Train Forêt aléatoire (
rf_reg) with default settings (100 trees, max depth 10).
| Model | R² | RMSE | MAE |
|---|---|---|---|
| Baseline (median) | -0.0540 | 1.1809 | 0.8813 |
| Linear regression | 0.5911 | 0.7356 | 0.5297 |
| Random forest | 0.7795 | 0.5401 | 0.3646 |
Three numbers. The rest of the session asks whether the third one is worth anything.
Step 2: Learning curve: would more data help?15 min
- Open the forest results, scroll to the Diagnostics tab.
- Learning curve → Compute. The same model is retrained on five growing samples, three folds each. On this dataset it takes about eighteen seconds and a progress bar tells you which fold it is on. You can cancel.
- Read the two curves and, under them, the sentence the studio computes.
The four possible readings, and what each one means for your next hour:
| Reading | What it means | What you do |
|---|---|---|
| The gap stays wide (0.10 or more) | the model memorises rather than generalises | simplify the model, or get more data |
| Both curves stay low, together | the model is too simple for this data | more data will not help; change the model or the features |
| Validation has plateaued | more data would add almost nothing | change the model, not the dataset |
| Validation still rising at the largest size | adding data should still gain score | go and get more data |
The plots are computed on folds taken inside the training part. Your test set is never looked at: it keeps its job, which is the final measurement.
Step 3: Cross-validation: is the number solid?12 min
- Cross-validation, k = 5, Compute. About twelve seconds on this dataset.
- Read the mean, the standard deviation across folds, and the sentence.
Reference run: R² mean 0.7786, standard deviation 0.0069 over 5 folds. The folds agree, so the 0.7795 of the single split is a real number and not an accident of one shuffle.
Now use it properly. Train a Gradient Boosting (gb_reg) and cross-validate it too. Then answer, in writing:
- Is the difference between your two models bigger than the standard deviation of either of them?
- If it is not, what have you actually demonstrated?
This is the question that separates a comparison from a coin flip, and it is the one nobody asks. On a dated dataset, remember Session 8: these folds are ordinary random folds, so their agreement measures stability inside the training period, not performance in the future.
Step 4: Validation curve: where overfitting starts13 min
- Validation curve. The hyperparameter selector is built from the registry: for Forêt aléatoire (
rf_reg) it offers Arbres (n_estimators, 10 to 500) and Profondeur max (max_depth, 1 to 40). - Choose Profondeur max and compute. Five to eight values between the registry bounds.
- Read where the training curve keeps rising while the validation curve turns down. That point is the entry into overfitting, and the studio names it in a sentence under the chart.
- Then try Arbres. Notice that the curve is nearly flat.
Two honest details about the budget. Past a compute budget the studio either caps the number of trees or shortens the axis, and it says which in a note under the curve. And it prefers a wide axis to a fine one: three values from 10 to 40 trees tell you more than five values from 10 to 14.
Write down the answer to: which of the two hyperparameters is worth your attention on this dataset, and how much score is at stake?
Step 5: Search, and apply without losing anything15 min
- Search, kind Grid, pick both hyperparameters. Up to 25 combinations. About 25 seconds here, and the note will tell you if the axis was shortened or the rows sampled.
- The result is a clickable heat map: one cell per combination, plus your current model marked on it.
- Read the sentence: it says how many points the best combination gains over yours. Below 0.005 it says so.
- Click the best cell, then Appliquer cette combinaison.
This does not modify your model. It creates a new one, on the same dataset, with the same features, the same preparation and the same split, and trains it. You keep both and compare them in the Comparison panel. Nothing you did is overwritten, ever.
- Cross-validate the new model too. Then answer the only question that matters: is the gain from tuning bigger than the fold-to-fold noise you measured in Step 3?
On this dataset the honest answer is usually "barely". Tuning is the last five percent. Sessions 7 and 9 showed you where the other ninety-five are: in the features. Run the search anyway, so that you can say it with a number rather than as an opinion.
Step 6: The Coach, and the model card10 min
Back on any results screen, the Coach block reads what is on screen and proposes at most six things. Its thresholds are the same as the "quality of fit" verdict just above it, so it never contradicts the screen.
| Rule | Fires when | One-click remedy |
|---|---|---|
| overfitting | train / test gap above 0.10 | max depth halved, or neighbours doubled, or C divided by 4 |
| underfitting | training score too low | max depth + 5, or trees doubled |
| low score | test low, no gap, not underfitting | try a random forest |
| missing scaling | no standardisation on a distance-based algorithm | turn standardisation back on |
| imbalance / majority | smallest class under a third of the largest | rebalance the classes |
| leak | a leak warning was raised | drop the offending variable |
Apply one. It creates a model named Coach: ..., comparable with the others. Then finish with the card:
- Results screen, Fiche tab. Intended use, data, split actually applied, preparation, algorithm and parameters, metrics, and computed limits.
- Click Désigner champion on your best model: one champion per project and per task, and the badge follows it into the comparison and the history.
- Download the card in Markdown and paste its limits section into the Conclusion et limites section of your report. Then add the one limit the card cannot know: the truncated target.
What you should have
- Four or five trained models on the same dataset, in one experiment
- A learning curve, read and acted upon
- Two cross-validations with their standard deviations, and a comparison judged against them
- A validation curve on the hyperparameter that matters
- A grid search, one combination applied as a new model
- One Coach remedy applied, one model card downloaded
- The
dep-12mission at 6 / 6
Deliverables
- Mission:
dep-12validated - Report: Modélisation and Évaluation sections, with the curves poured in
- One sentence: given your cross-validation spread, how much of a difference between two models would you refuse to call a difference?
Bonus
- Open the Error map tab on your best regression. Find the horizontal wall at 5.0 and count how much of your RMSE it accounts for.
- Run the search in Random mode instead of Grid and compare what twenty draws find against what twenty-five grid points find.
- Set
max_depthto 40 on a decision tree overdigits: train 1.000, test 0.824. Then let the Coach halve it. That is overfitting you can see in two numbers.
Resources
- Session 12 slides (the lecture this practical work follows)
- Course page: both programmes, all fifteen sessions
- rakoon-ds studio
missions/dep-12.json