Understand the idea
Training examples influenced fitting. Evaluation on separate rows asks whether the learned relationship transfers. A low training error can coexist with a large unseen error.
Python skill: Subtract aligned pandas columns and distinguish training error from validation error.
Meet the syntax
pd.DataFrame
errors['validation_rmse'] - errors['train_rmse']pd.DataFrame- Builds a small table from named columns and lists of their values.
errors['validation_rmse'] - errors['train_rmse']- Subtracts row by row using matching model labels; a positive gap means larger validation error.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
errors = pd.DataFrame({'train_rmse': [1, 4], 'validation_rmse': [8, 5]}, index=['A', 'B'])
answer = errors['validation_rmse'] - errors['train_rmse']
This practice: Read and run the Python. Next: Change · Seen is not unseen.
Given data · LINE24
24 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| distance | duration |
|---|---|
| 1 | 5.30501 |
| 1.47826 | 11.2361 |
| 1.95652 | 11.8488 |
| 2.43478 | 14.809 |
| 2.91304 | 10.7589 |
| 3.3913 | 19.4972 |
| 3.86957 | 17.89 |
| 4.34783 | 15.531 |
Column meanings and units
Column names describe the supplied features and target. Keep the stated units and row identities when making comparisons.
Synthetic data are deliberately small and reproducible. Their patterns illustrate an idea; they are not evidence about a real population.
| Column | Stored type |
|---|---|
| distance | float64 |
| duration | float64 |
Your task · Follow
Model A has training/validation RMSE 1/8; model B has 4/5. Store validation minus training RMSE for each model in a Series named answer, indexed A then B.
Hint 1 — Think
Subtract aligned pandas columns and distinguish training error from validation error.
Hint 2 — Tools
Use pd.DataFrame, errors['validation_rmse'] - errors['train_rmse']. Read the visible syntax meanings before editing.
Hint 3 — Approach
Model A has training/validation RMSE 1/8; model B has 4/5. Store validation minus training RMSE for each model in a Series named answer, indexed A then B. Keep the supplied row order and inspect the named output after running.
Explained solution
errors = pd.DataFrame({'train_rmse': [1, 4], 'validation_rmse': [8, 5]}, index=['A', 'B'])
answer = errors['validation_rmse'] - errors['train_rmse']
A has a gap of 7 and B a gap of 1. B also has the lower validation RMSE in this example. Training rows taught the model; validation rows ask about new examples. A gap alone does not select a model: compare the validation error itself on the same rows.
Helpful prior knowledge: Measuring prediction error These links are guidance, not locks.
Sources and API context
Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.