// 121 cards · 9 categories

Cheatsheets.

Every formula, metric and rule from the course on one page, grouped by category. Filter to what you're revising, or print it.

Formulas

The equations to know by heart, with what each symbol means.

Population risk

: expected loss over the unknown population. Cannot be computed.
1.5 Empirical Risk and Population Risk →

Empirical risk

: average loss on the sample.
1.5 Empirical Risk and Population Risk →

Generalisation gap

. Estimated with held-out data.
1.5 Empirical Risk and Population Risk →

ERM

. OLS = ERM + squared loss; logistic = ERM + cross-entropy.
2.2 Empirical Risk Minimisation (ERM) →

Bias–variance decomposition

.
2.5 The Bias–Variance Trade-off →

Standardisation

with from the training set only, reused for validation and test.
2.8 Data Leakage and Good ML Practices →

Residual

(observed − fitted). Positive → model under-predicted.
3.1 Regression Fundamentals →

Multiple linear regression

; prediction .
3.2 Simple and Multiple Linear Regression →

RSS

.
3.3 Ordinary Least Squares (OLS) →

OLS normal equations

(if invertible).
3.3 Ordinary Least Squares (OLS) →

Design matrix shape

: , first column ones. : . : .
3.3 Ordinary Least Squares (OLS) →

2×2 inverse

3.3 Ordinary Least Squares (OLS) →

Simple regression by hand

, .
3.4 Calculating Regression Coefficients by Hand →

Standard errors

, . Simple: .
3.8 Standard Errors, Confidence Intervals and p-values →

t-test & CI

, df . CI: (≈ ±2 SE).
3.8 Standard Errors, Confidence Intervals and p-values →

VIF

, from on other predictors. Worry > 5–10.
3.9 Multicollinearity and VIF →

Odds & log-odds

odds ; logit . .
4.2 Odds, Log-odds and the Sigmoid Function →

Sigmoid

. ; .
4.2 Odds, Log-odds and the Sigmoid Function →

Decision boundary

Predict 1 if (0 when ). Linear.
4.3 The Logistic Regression Model →

Logistic log-likelihood

. Maximise ⇔ minimise cross-entropy.
4.4 Maximum Likelihood Estimation →

Wald test

, reject if . OR CI: .
4.4 Maximum Likelihood Estimation →

Cost-optimal threshold

Alert if . Costlier misses → lower threshold.
4.9 Threshold Selection and Classification Costs →

Expected cost

; choose on validation data.
4.9 Threshold Selection and Classification Costs →

Regularised objective

, .
5.1 Why Regularisation is Needed →

Model counts

Best subset: . Stepwise: .
5.3 Best Subset and Stepwise Selection →

Ridge

; . Orthonormal: .
5.4 Ridge Regression (L2) →

LASSO

. Orthonormal: (soft threshold).
5.5 LASSO Regression (L1) →

Norms

= #non-zeros; ; (intercept excluded).
5.8 Mathematical Objectives and Worked Calculations →

Regularised logistic

(ridge) or (LASSO).
5.8 Mathematical Objectives and Worked Calculations →

K-means objective

(WCSS). Local minimum only.
6.1 K-means Clustering →

Distances

Euclidean ; Manhattan . K-means compares squared Euclidean.
6.2 Distance Calculations and Cluster Assignment →

SVM decision rule

; predict . Labels .
6.4 SVM Fundamentals →

SVM geometry

Boundary ; margins . Distance . Width .
6.5 Margins and Support Vectors →

Hard-margin SVM

s.t. .
6.6 Hard-margin and Soft-margin SVM →

Soft-margin SVM

, . ≡ hinge + L2, .
6.6 Hard-margin and Soft-margin SVM →

Kernels

Linear · Polynomial · RBF .
6.7 The C Parameter and Kernels →

Evaluation metrics

How to measure a model, and when each measure misleads.

MAE / RMSE

MAE (robust). RMSE (punishes big errors). Both in units of .
3.7 R², Adjusted R², RMSE and Other Metrics →

R²

, . Share of the mean-baseline's error removed.
3.7 R², Adjusted R², RMSE and Other Metrics →

Adjusted R²

. Falls when a useless predictor is added.
3.7 R², Adjusted R², RMSE and Other Metrics →

Out-of-sample R²

Baseline is on test data. Can be negative.
3.7 R², Adjusted R², RMSE and Other Metrics →

Confusion matrix

Rows actual, columns predicted. TP hit · FN miss · FP false alarm · TN. FP = Type I, FN = Type II.
4.6 The Confusion Matrix →

Sensitivity / recall / TPR

: share of actual positives caught.
4.7 Accuracy, Precision, Recall and Specificity →

Specificity / TNR

: share of actual negatives cleared. FPR spec.
4.7 Accuracy, Precision, Recall and Specificity →

Precision / PPV

: share of flagged cases truly positive. Depends on prevalence.
4.7 Accuracy, Precision, Recall and Specificity →

Accuracy & F1

Acc . .
4.7 Accuracy, Precision, Recall and Specificity →

ROC & AUC

ROC: TPR vs FPR over all thresholds. AUC = P(random positive scored above random negative). 0.5 random, 1 perfect.
4.10 ROC Curve and AUC →

Loss functions

What each loss punishes and where it is used.

Squared loss (L2)

. Punishes big errors; outlier-sensitive; OLS, ridge, LASSO.
2.1 Loss Functions and Risk →

Absolute loss (L1)

. Linear; robust to outliers; MAE.
2.1 Loss Functions and Risk →

Cross-entropy / log loss

. Logistic regression. Confidently wrong = huge loss.
2.1 Loss Functions and Risk →

0–1 loss

. Averages to the error rate; not smooth.
2.1 Loss Functions and Risk →

Log-loss values

: 0.99→0.01, 0.9→0.105, 0.5→0.693, 0.1→2.303, 0.01→4.6.
4.5 Cross-entropy / Log-loss →

Hinge loss

. 0 beyond the margin; 0–1 inside; >1 if misclassified.
6.6 Hard-margin and Soft-margin SVM →

Data leakage & good practice

How evaluation goes wrong, and the rule that fixes each case.

Train / validation / test

Train: fit parameters. Validation: choose models & hyperparameters. Test: final estimate, used once.
2.6 Training, Validation and Test Sets →

CV with preprocessing

Scaling, imputation, feature selection and oversampling happen inside each fold, on that fold's training part only.
2.7 Cross-validation →

The six leaks

1 Test reuse · 2 Preprocess before split · 3 Feature selection before CV · 4 Related records across splits · 5 Time leakage · 6 Target leakage.
2.8 Data Leakage and Good ML Practices →

Six golden rules

Split before preprocessing. Never tune on test. Select features inside folds. Keep related rows together. Respect time order. Use only prediction-time features.
2.8 Data Leakage and Good ML Practices →

One test for every leak

Did anything from held-out data, the future, or the outcome influence a calculation or decision before the final score? If yes → leak.
2.8 Data Leakage and Good ML Practices →

Oversampling rule

Split first. Oversample only the training part (inside each CV fold). Evaluate on the original class ratio.
4.11 Class Imbalance →

Regularisation & leakage

Standardise within training folds. Never choose λ on the test set.
5.9 Selecting λ Using Cross-validation →

Interpreting models

Ready-made sentences for explaining coefficients, p-values and plots.

Diagnose from errors

Train low, val high → overfit. Both high → underfit. Train & val good, test bad → shift / leakage / evaluation issue.
2.3 Underfitting and Overfitting →

Coefficient sentence

"Holding the other predictors fixed, a one-unit increase in is associated with a change in predicted ."
3.5 Interpreting Coefficients →

Residual plot patterns

Random cloud → OK. Curve → missing nonlinearity. Fan → heteroskedasticity. Waves in time → autocorrelation. Heavy tails → outliers / non-normal.
3.6 Residuals and Regression Assumptions →

p-value sentence

"If the true coefficient were zero (and assumptions hold), a t-statistic at least this extreme would occur with probability p."
3.8 Standard Errors, Confidence Intervals and p-values →

Multicollinearity effects

Inflated SEs, unstable/wrong-sign coefficients. Predictions often fine. Fix: drop/combine, more data, ridge.
3.9 Multicollinearity and VIF →

Logistic coefficient

: change in log-odds per unit . : odds ratio (multiplies the odds). Not a constant change in probability.
4.3 The Logistic Regression Model →

Threshold effects

Lower → more flagged → sens ↑, spec ↓, FN ↓, FP ↑, precision usually ↓. Raise → the reverse.
4.8 Sensitivity and Specificity Trade-offs →

Ridge properties

Shrinks, never zero. Always solvable. Shares credit among correlated predictors. Bias ↑, variance ↓ with λ.
5.4 Ridge Regression (L2) →

λ regimes

λ=0: OLS, min training error. Small: slight shrink, test often ↓. Middle: best (CV). Large: high bias. ∞: predicts .
5.6 Understanding λ (Lambda) →

K-means failure modes

Unscaled features · bad starts (local optima) · wrong K · non-round clusters · outliers · categorical data.
6.3 Updating Centroids and Convergence →

Effect of C

Large C: narrow margin, few violations, low bias/high variance. Small C: wide margin, high bias/low variance. C ~ 1/λ.
6.7 The C Parameter and Kernels →

Algorithms step by step

The procedures you may be asked to run by hand.

ML workflow

Define problem → explore data → split → fit candidates on train → compare on validation/CV → inspect & revise → test once → deploy & monitor.
1.3 The ML Modelling Process →

K-fold CV

1) Split into folds. 2) For each fold: train on , validate on it. 3) Average the errors. 4) Pick the best candidate; re-fit on all training data.
2.7 Cross-validation →

"Is this approach reasonable?"

1) Identify the problem. 2) Name the leak. 3) Explain the consequence (optimistic estimate). 4) Recommend the fix.
2.8 Data Leakage and Good ML Practices →

Slope by hand

1) Means . 2) Deviations. 3) Products & squares. 4) Sum → , . 5) Divide; then intercept. 6) Check residuals sum to 0.
3.4 Calculating Regression Coefficients by Hand →

AUC by counting

For every (positive, negative) pair, score 1 if the positive ranks higher, 0.5 if tied. AUC = total / (#pos × #neg).
4.10 ROC Curve and AUC →

Imbalance toolkit

Right metrics + majority baseline · cost-based threshold · oversample/undersample training data · class weights.
4.11 Class Imbalance →

Forward stepwise

Start . Repeatedly add the predictor that most lowers RSS → . Choose the size by validation/CV.
5.3 Best Subset and Stepwise Selection →

Best subset

For each , best of models by RSS → . Pick among by CV / adj. / AIC / BIC. Cost .
5.3 Best Subset and Stepwise Selection →

Penalised objective by hand

1) Compute RSS (or ). 2) Compute the norm of the slopes. 3) Add λ × norm. Compare candidates on the same λ.
5.8 Mathematical Objectives and Worked Calculations →

Choosing λ

Split off test → log-spaced λ grid → K-fold CV (standardise inside folds) → pick min CV or 1-SE → refit on all training → test once.
5.9 Selecting λ Using Cross-validation →

K-means

1) Initialise K centroids. 2) Assign each point to the nearest centroid. 3) Move each centroid to its cluster mean. 4) Repeat until assignments stop changing.
6.1 K-means Clustering →

Choosing K

Not by min (falls with K). Use the elbow, silhouette, stability and usefulness.
6.3 Updating Centroids and Convergence →

SVM by hand (2 support vectors)

Use symmetry for the direction of ; set at the negative SV and at the positive SV; solve; width .
6.5 Margins and Support Vectors →

Comparisons

Side-by-side differences between methods that are easy to mix up.

Supervised vs unsupervised

Supervised: have and ; learn (regression, classification). Unsupervised: only ; find structure (clustering).
1.2 Types of Machine Learning →

Parametric vs non-parametric

Parametric (linear/logistic regression): fixed shape, few parameters, less data, interpretable, risk of bias. Non-parametric (K-NN): flexible, needs more data, risk of variance.
1.2 Types of Machine Learning →

Loss vs metric

Loss: minimised during fitting (must be convenient). Metric: judges the final model for the task (AUC, cost, RMSE).
2.1 Loss Functions and Risk →

Simple vs flexible

Simple: high bias, low variance, underfits. Flexible: low bias, high variance, overfits.
2.5 The Bias–Variance Trade-off →

Linear vs logistic regression

Linear: number, models , OLS, RMSE/. Logistic: class via , linear in log-odds, MLE, confusion matrix/AUC.
4.1 Regression versus Classification →

OLS vs MLE fitting

OLS: minimise RSS, closed form. Logistic MLE: maximise log-likelihood, numerical (concave, no bad local optima).
4.4 Maximum Likelihood Estimation →

Ridge vs LASSO in one line

Ridge divides (never zero); LASSO subtracts (exact zeros → selection).
5.5 LASSO Regression (L1) →

Subset vs ridge vs LASSO

Zeros: yes / no / yes. Closed form: no / yes / no. Cost: / easy / moderate. Correlated: arbitrary / shares / picks one.
5.7 Ridge versus LASSO →

K-means vs K-NN

K-means: unsupervised, K = clusters. K-NN: supervised, K = neighbours.
6.1 K-means Clustering →

Logistic regression vs linear SVM

Labels 0/1 vs ±1 · cross-entropy vs hinge · probability vs score · all points vs support vectors · λ vs C · features vs kernels.
6.4 SVM Fundamentals →

Complexity knobs, all models

More complex: ↑ degree, ↑ #features, ↓ λ, ↓ K (K-NN), ↑ C, ↑ γ (RBF), ↑ tree depth.
6.7 The C Parameter and Kernels →

Core concepts

One-line definitions of the big ideas.

Machine learning

Learning a prediction rule from data so that predicts well on new data.
1.1 What is Machine Learning? →

Features vs target

Features / predictors : the inputs. Target / response / label : what we predict.
1.1 What is Machine Learning? →

Regression vs classification

Regression predicts a number. Classification predicts a category.
1.2 Types of Machine Learning →

Hyperparameter

A setting chosen by you, not fitted from data (degree, depth, , , ). Choose it on validation data or by CV.
1.3 The ML Modelling Process →

No Free Lunch

Averaged over all problems no algorithm wins. In practice: no universally best model, so compare candidates on relevant data and state your assumptions.
1.4 Fundamental Limits of Machine Learning →

Generalisation gap drivers

↑ complexity → ↑ gap. ↑ data → ↓ gap. ↑ regularisation → ↓ gap. ↑ noise → ↑ gap.
2.4 Generalisation and the Generalisation Gap →

Typical splits

60:20:20 or 50:25:25 (train:val:test); train:val 50–80% / 20–50%. A design choice.
2.6 Training, Validation and Test Sets →

Signal + noise

, . Linear regression: .
3.1 Regression Fundamentals →

OLS noise assumptions

Mean zero · constant variance · independent · (roughly normal for t-tests).
3.6 Residuals and Regression Assumptions →

When to regularise

or · correlated predictors · noisy data.
5.1 Why Regularisation is Needed →

Complexity dials

#features, |β|, degree, tree depth, small K (K-NN), large K (K-means), large C (SVM).
5.2 Model Complexity and Feature Selection →

Why LASSO gives zeros

L1 constraint = diamond with corners on the axes; RSS ellipses usually touch a corner first.
5.7 Ridge versus LASSO →

Support vectors

Points on (or inside) the margin. They alone determine the boundary.
6.5 Margins and Support Vectors →

Common traps

Mistakes that cost marks, and the correct statement.

NFL misreading

Wrong: "all algorithms do equally well on my data". Right: it is an average over every possible problem; real problems have structure.
1.4 Fundamental Limits of Machine Learning →

Training error picks complexity

Wrong: choose the model with the lowest training error. Right: choose on validation data or by CV.
2.3 Underfitting and Overfitting →

"Variance" means...

Variance of the fitted model across training sets, not the variance of the data.
2.5 The Bias–Variance Trade-off →

"Linear" regression

Linear in the coefficients, not the inputs. , , are allowed.
3.2 Simple and Multiple Linear Regression →

Comparing coefficients

Raw sizes depend on units. Standardise predictors first. And association ≠ causation.
3.5 Interpreting Coefficients →

R² misreadings

Not "% correct". High in-sample ≠ good prediction. Low ≠ useless predictors.
3.7 R², Adjusted R², RMSE and Other Metrics →

p-value misreadings

Not P( true). Not effect size. Large p ≠ no effect.
3.8 Standard Errors, Confidence Intervals and p-values →

Odds ratio 2 ≠ "twice as likely"

It doubles the odds. The probability ratio is smaller unless is small.
4.3 The Logistic Regression Model →

Sign of the log-likelihood

is maximised (≤ 0). Cross-entropy is minimised (≥ 0).
4.5 Cross-entropy / Log-loss →

High accuracy, rare class

Compare with the majority-class baseline. Report sensitivity, specificity, precision.
4.7 Accuracy, Precision, Recall and Specificity →

AUC misreadings

AUC 0.9 ≠ 90% accuracy. It doesn't choose a threshold or account for costs.
4.10 ROC Curve and AUC →

Select by p-values

Dropping and refitting ignores selection uncertainty and over-states significance. Use CV stepwise or LASSO.
5.2 Model Complexity and Feature Selection →

Lowest training error?

Always at λ = 0. Regularisation never beats OLS on training RSS.
5.6 Understanding λ (Lambda) →

Unscaled features

The largest-range feature dominates distances. Standardise before K-means, K-NN, SVM.
6.2 Distance Calculations and Cluster Assignment →