A place to look things up when a symbol or a scikit-learn argument stops making sense mid-chapter.
Core vocabulary¶
- Feature / predictor / independent variable
- An input column of the design matrix . The three names are used interchangeably in this book, depending on whether the sentence is written from a machine-learning or a statistics perspective.
- Target / response / label / dependent variable
- The quantity we want to predict. Label is normally reserved for classification.
- Training set
- The data used to estimate the model parameters.
- Test set
- Data held back and touched only once, at the very end, to obtain an unbiased estimate of generalisation performance.
- Validation set
- Data used during model development to compare models or tune hyperparameters. Because you look at it repeatedly, it stops being an unbiased estimate of the test error.
- Parameter
- A quantity learned from the data, e.g. the coefficients of a regression.
- Hyperparameter
- A quantity fixed by you before training, e.g. the regularisation strength , the number of folds , or a tree’s
max_depth. - Bias
- Error caused by a model being too rigid to represent the true relationship. See ⚖️ Bias-Variance Tradeoff.
- Variance
- Sensitivity of the fitted model to the particular training sample that was drawn.
- Irreducible error
- Noise in the data itself. No model can go below it.
- Overfitting
- Fitting structure that is specific to the training sample and does not generalise. Low training error, high test error.
- Underfitting
- The model is not flexible enough to capture the real structure. High training and test error.
- Discriminative model
- Models directly (logistic regression, SVM, trees).
- Generative model
- Models and , then applies Bayes’ theorem (LDA, QDA, Naïve Bayes).
- Kernel
- A function that computes inner products in an implicitly higher-dimensional space, letting a linear method draw non-linear boundaries.
Symbols used throughout¶
| Symbol | Meaning |
|---|---|
| number of observations | |
| number of predictors | |
| number of folds in cross-validation (also number of classes in some chapters) | |
| design matrix, shape | |
| target vector, length | |
| regression coefficients | |
| the estimated function | |
| predicted values | |
| error / noise term | |
| noise variance (the irreducible error) | |
regularisation strength (called alpha in scikit-learn) | |
elastic net mixing parameter (called l1_ratio in scikit-learn) | |
| prior probability of class | |
| mean vector of class | |
| covariance matrix | |
| discriminant function for class | |
| learning rate in boosting |
Metrics¶
| Metric | Formula | Used for |
|---|---|---|
| MSE | regression | |
| RMSE | regression, in the units of | |
| R² | regression | |
| Accuracy | classification (balanced classes) | |
| Precision | “when I say positive, how often am I right?” | |
| Recall | “of all real positives, how many did I catch?” | |
| F1 | classification with imbalanced classes |
Naming traps in scikit-learn¶
The standard workflow¶
Almost every chapter is a variation on the same five steps:
Split — hold out a test set before doing anything else.
Preprocess — fit scalers/encoders on the training data only, ideally inside a
Pipeline.Select — compare models and hyperparameters with cross-validation on the training data.
Fit — refit the chosen model on the full training data.
Evaluate — score once on the held-out test set and report that number.