Machine Learning, FoundationsLesson 11 of 92

Module 2 · Linear models and the machinery of fitting

There is an exact answer, and we usually refuse it

In this lesson

  • 8 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 2 of 10 in this chapter

This chapter’s goalFit and diagnose a linear or logistic model end to end: compute its loss by hand on a handful of rows, tune the learning rate from the shape of the loss curve, state what a coefficient does and does not mean in the units of the data, and explain what ridge and lasso penalties change about the fitted parameters.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:58Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

The formula that ends the search

For linear regression with squared error, you do not need to search at all. There is an exact solution, written in one line of linear algebra:

Text
w = (X'X)^-1 X'y

where X' is the transpose and ^-1 is the matrix inverse. This is the normal equation, and it gives the parameters that minimise MSE exactly, in one step, with no learning rate, no iterations and no convergence to worry about.

Python
import numpy as np
X = np.array([[50], [70], [90], [110], [130]])
X1 = np.hstack([np.ones((5, 1)), X])          # add the intercept column
y = np.array([32, 44, 51, 67, 74])
np.linalg.solve(X1.T @ X1, X1.T @ y)          # array([6.15, 0.525])

Exactly the numbers scikit-learn returned. In fact LinearRegression does something very close to this internally: it uses a numerically safer routine called least squares via SVD, but the spirit is the same. There is no gradient descent inside it.

So why does every course teach gradient descent?

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘There is an exact answer, and we usually refuse it’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/the-closed-form-and-why-we-leave-it (Accessed: 29 November 2026).