Skip to content
BIASED

Least squares

Block 1 of 8~2 min

One formula for all the data

The topic Nearest neighbours predicts from nearby examples. Least squares instead fits one rule for the whole sample. Its prediction is a(x)=w⊤xa(x)=w^\top x; a column of ones supplies an intercept. The design matrix X∈Rn×dX\in\mathbb R^{n\times d} contains the features, and y∈Rny\in\mathbb R^n contains the targets.

“Linear” means linear in the unknown weights. Columns may contain xx, x2x^2 or log⁡x\log x on its domain. Their values must be computable before choosing the weights. A weight inside ewxe^{wx} does not meet this condition.

The objective is the average squared residual,

Q(w)=1n∥Xw−y∥2.Q(w)=\frac1n\lVert Xw-y\rVert^2.

Multiplying it by a positive constant leaves its minimizer unchanged. Squared error has convenient geometry, but it also gives large residuals a large influence. We will connect the fitting rule, its assumptions and its validation.

Answers are saved on the server and tied to this browser until you sign in.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • Least squares: projection and validationoptional

    Check normal equations and residual orthogonality, then compare training and validation on original synthetic data.

    ~20 min · easier on a computer · Least squares topic read.

    Self-check in the notebook — not part of mastery or the certificate.