Linear Regression as Learning
Fitting by choosing the parameters that minimise the mean squared error: the simplest model that learns from data.
Needs a step first: 26
Linear regression already has every part of machine learning: a model with parameters, a loss that measures how wrong it is on the data, and a way to make the loss small. Here the loss is the mean squared error, and it can be minimised exactly with the normal equations from least squares or step by step with gradient descent; both reach the same answer because the loss is convex. With many inputs, , it is a single neuron with no activation. Logistic regression and neural networks change the model and the loss but keep this recipe.
Where it shows up: Its model–loss–optimiser recipe is the template for logistic regression, neural networks and every model after them.
How to hold it: In your head
See model, loss and minimisation as the recipe every learning method follows, here in its simplest form: a single neuron with no activation.
What knowing it looks like
- Fit a line to three or four points by hand and check that the residuals sum to zero.
- Write the gradient of the mean squared error with respect to and and take one gradient step.
- Explain why the normal equations and gradient descent give the same answer here.
Test yourself
Fit to the points , , by least squares. Then check that both partial derivatives of the mean squared error are zero at your answer.
Show the worked answer
Needs a step first: 26
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Linear Regression as Learning" (Undergraduate II tier): Fitting $\hat y = wx + b$ by choosing the parameters that minimise the mean squared error: the simplest model that learns from data. I already know: Least Squares, Correlation and Regression, Gradient Descent. Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away. Finish by testing me with this: Fit $\hat y = wx + b$ to the points $(0, 1)$, $(1, 2)$, $(2, 4)$ by least squares. Then check that both partial derivatives of the mean squared error $L = \frac13\sum(wx_i + b - y_i)^2$ are zero at your answer. Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.
Needs first
- Least SquaresThe best approximate solution of a system with too many equations: the one whose errors have the smallest sum of squares.Undergraduate I · Linear Algebra
- Correlation and RegressionMeasuring how closely two quantities move together, and fitting the straight line that best predicts one from the other.Core · Probability & Statistics
- Gradient DescentRepeatedly stepping against the gradient, , to walk downhill towards a minimum.Undergraduate I · Optimisation & Information
Leads to
- Logistic Regression and ClassificationA linear score passed through the sigmoid to give a probability, trained by minimising cross-entropy.Undergraduate II · Machine Learning
- Overfitting and RegularisationA model that fits its training data too closely does worse on new data; regularisation trades a little training fit for better generalisation.Undergraduate II · Machine Learning
On the way to
Recommended
- Neural Networks: Zero to HeroAndrej Karpathy · VideosFree lectures that build backpropagation, a language model and a small GPT from scratch in Python, explaining every line.
- Understanding Deep LearningSimon J. D. Prince (MIT Press) · BookA clear, well-illustrated 2023 textbook covering networks, training, transformers, diffusion models and reinforcement learning, free as a PDF with Python notebooks.
- 动手学深度学习阿斯顿·张、李沐等 · Book · 中文The Chinese edition of Dive into Deep Learning: a free textbook in which every model, from linear regression to transformers, runs as code beside the maths.
- 跟李沐学AI李沐 · Videos · 中文Mu Li's own Bilibili channel: the video course for Dive into Deep Learning and paragraph-by-paragraph readings of key papers, including the Transformer paper.