Skip to content

Phase 3 - Supervised Learning - Regression

Regression is where supervised learning becomes concrete. Everything in this phase — the cost function, the gradient, the penalty term, the held-out score — reappears unchanged in classification, in ensembles, and in every neural network in the Deep Learning module. Learn it properly once here and the rest of the curriculum is mostly variations.

What this phase covers

Eight pages, in dependency order. Each builds on the one before, and each hand-works its arithmetic on the same five-point dataset so the numbers stay comparable across the whole phase.

#PageCore ideaHand-worked result
1Introduction to Regression AnalysisThe model is a dot product; always beat a baselineRMSE 23.8 on three houses
2Simple Linear RegressionDerive slope and intercept from two derivativesy^=0.6x+2.2\hat{y} = 0.6x + 2.2
3Multiple Linear RegressionThe Normal Equation; interpreting coefficientsθ=[4.25,2.25,1.25]\boldsymbol{\theta} = [4.25, 2.25, 1.25]
4Polynomial RegressionCurves from a linear model, and how to pick the degreey^=10.2x+2x2\hat{y} = 1 - 0.2x + 2x^2
5Cost Functions - MSEWhat you optimise, and what that choice costsMSE 0.48, MAE 0.64
6Gradient Descent ExplainedIterate to the minimum; learning-rate stabilityTwo steps: 17.20 → 6.27 → 2.55
7Regularization - Ridge and LassoShrink coefficients; L1 selects, L2 does notLasso at λ=10\lambda{=}10: [1.0,0][1.0, 0]
8Metrics - R² and Adjusted R²Report honestly; know when a number liesR2=0.60R^2 = 0.60, adjusted 0.467

The path through

diagram Diagram mermaid

Two threads run in parallel and meet at regularisation. The modelling thread goes simple → multiple → polynomial, adding capacity. The optimisation thread goes cost function → gradient descent, explaining how any of it is computed. Regularisation needs both: it modifies the cost, and it exists because extra capacity overfits.

Before you start

You will get much more from this phase if you already have:

None of these is a hard prerequisite. Every derivation on these pages is worked out in full, and every result is checked against NumPy or scikit-learn.

What you’ll be able to do afterwards

By the end of this phase you should be able to:

  1. Derive the least-squares solution for one feature from scratch, and explain why the fitted line passes through the centroid.
  2. Write the Normal Equation, say why lstsqlstsq is preferred over matrix inversion, and diagnose multicollinearity with a variance inflation factor.
  3. Choose between MSE, MAE and Huber based on what your errors actually cost.
  4. Pick a learning rate deliberately — including computing the value above which descent diverges.
  5. Explain, geometrically, why Lasso produces exact zeros and Ridge does not.
  6. Report a model with RMSE and R2R^2 on held-out data, and recognise when either is misleading.

How long it takes

ActivityTime
Reading the eight pages3–4 hours
Working the hand examples with pen and paper2 hours
Running the code and the 40 exercises3–4 hours
The practice project below3–5 hours
Total11–15 hours

The hand examples are the part people skip and the part that makes the difference. All of them use small integers deliberately — you can do every one on the back of an envelope.

Practice project

Predict California housing prices, using sklearn.datasets.fetch_california_housingsklearn.datasets.fetch_california_housing (20,640 rows, 8 features). A sensible progression:

  1. Establish the DummyRegressor(strategy="mean")DummyRegressor(strategy="mean") baseline. Write the number down.
  2. Fit plain LinearRegressionLinearRegression. Report RMSE and R2R^2 on a held-out split.
  3. Plot residuals against fitted values. The curvature you find is the reason for step 4.
  4. Add PolynomialFeatures(2)PolynomialFeatures(2) inside a pipeline with StandardScalerStandardScaler. Compare cross-validated scores against step 2.
  5. Add RidgeCVRidgeCV and LassoCVLassoCV. Check how many features Lasso keeps.
  6. Write three sentences that a non-technical colleague could act on.

Everything you need is covered across the eight pages, and step 6 is not optional — a model nobody can act on is not finished.

quizCheck yourself
  1. Which page should you read before Gradient Descent?

    Show answer

    B — Cost Functions, because gradient descent minimises the cost that page defines — Gradient descent walks downhill on a surface. Cost Functions defines that surface, proves it is convex, and explains what its gradient looks like.

  2. What single dataset is hand-worked across this entire phase?

    Show answer

    B — A five-point ad-spend and sales set chosen so every intermediate value is exact — x = 1..5 and y = 2, 4, 5, 4, 5. Slope 0.6, intercept 2.2, SSE 2.4, R-squared 0.6 — all exact, all reused, so results stay comparable from page to page.

  3. Why does this phase matter beyond regression itself?

    Show answer

    B — Cost functions, gradients, regularisation and held-out evaluation carry over unchanged to classification, ensembles and neural networks — Swap squared error for log loss and almost everything here applies to logistic regression; add layers and it applies to deep learning. The optimisation and evaluation machinery is universal.

Next

Start with Introduction to Regression Analysis — the vocabulary, the general model, and the baseline you will compare everything against.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did