Advanced Mathematics

Linear Regression as Learning

Fitting y^=wx+b\hat y = wx + b 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, y^=w⃗⋅x⃗+b\hat y = \vec w\cdot\vec x + b, 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 ww and bb and take one gradient step.
  • Explain why the normal equations and gradient descent give the same answer here.

Test yourself

Fit y^=wx+b\hat y = wx + b to the points (0,1)(0, 1), (1,2)(1, 2), (2,4)(2, 4) by least squares. Then check that both partial derivatives of the mean squared error L=13∑(wxi+b−yi)2L = \frac13\sum(wx_i + b - y_i)^2 are zero at your answer.
Show the worked answer
xˉ=1\bar x = 1, yˉ=73\bar y = \tfrac73. w=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2=(−1)(−43)+0+(1)(53)2=32w = \frac{\sum(x_i - \bar x)(y_i - \bar y)}{\sum(x_i - \bar x)^2} = \frac{(-1)(-\frac43) + 0 + (1)(\frac53)}{2} = \frac32, and b=yˉ−wxˉ=73−32=56b = \bar y - w\bar x = \tfrac73 - \tfrac32 = \tfrac56. Predictions 56,73,236\tfrac56, \tfrac73, \tfrac{23}6 give residuals −16,13,−16-\tfrac16, \tfrac13, -\tfrac16. ∂L∂b=23∑ri=0\frac{\partial L}{\partial b} = \frac23\sum r_i = 0 and ∂L∂w=23∑rixi=23(0+13−13)=0\frac{\partial L}{\partial w} = \frac23\sum r_i x_i = \frac23(0 + \tfrac13 - \tfrac13) = 0.

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.

On the way to

Recommended