Least squares: the design matrix, the normal equations and the geometry
10 questions on the design matrix, normal equations, pseudo-inverse, the role of the bias weight, residual variance and the projection picture.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
In the fitted model, what does the constant offset, or bias weight, compensate for?
- The number of training examples
- The largest error in the training data
- The difference between the average of the targets and the weighted combination of the averages of the basis functions
Sample 2
How can the least-squares solution be described geometrically?
- As the point farthest from the targets
- As the orthogonal projection of the vector of target values onto the space spanned by the basis function vectors
- As the average of all the target vectors
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
Fitting a line or a curve by least squares is one of the oldest procedures in science, and also one of the best understood. It has a closed-form answer: write down a set of equations, solve them, and the best weights appear, with no iteration and no tuning. Behind the answer lie three different ways of looking at the problem: the way of the data table, which says how to organise the numbers; the way of probability, which links least squares to an assumption about noise; and the way of geometry, in which the fit is a shadow of the data on a flat surface. Each view explains something the others hide.
This quiz starts with the practical machinery. You will see how the training data and the basis functions are arranged into a single table, the design matrix, and what the so-called normal equations and the pseudo-inverse do with it. You will look at what the constant offset in the model has to compensate for, and at what the maximum likelihood estimate of the noise level turns out to be once the curve has been fitted. These details turn up in every regression library you will ever use, so it is worth knowing what they mean.
The geometric part is the most illuminating. Think of all the target values together as a single point in a space with one dimension per data point. The possible predictions of the model fill a flat subspace of that space, and the least-squares fit is the point of the subspace closest to the data. The quiz asks what that means and what it says about the error. It then turns to trouble: when two basis functions are nearly copies of each other, the equations become unstable and weights can grow enormous, and the quiz asks how that is detected and cured.
Common misunderstandings include thinking that the normal equations are a trick for speed rather than the exact solution, that the pseudo-inverse is only for square tables, and that duplicated features are harmless. Many also forget that a high weight can be a symptom of a data problem and not a sign of an important feature. Knowing these views also helps with debugging. If a fitted model has gigantic weights that nearly cancel out, the geometry says that two directions in the data are almost the same, and the remedy is to remove or combine features, or to add a penalty. A short mental checklist follows from the quiz: arrange the data, solve the equations, inspect the leftover scatter, and distrust weights that look implausibly large.
The quiz suits students and practitioners who want to understand what a regression routine does. It uses no algebra. There are 10 questions, each explained straight after you answer, and the quiz takes about four minutes.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation appears after every answer.
›Do I need linear algebra?
No. Words like matrix and subspace are explained through pictures and tables. You will never be asked to multiply matrices or solve equations, only to say what a quantity means or what happens in a described situation.
›What is the design matrix?
It is the table that holds the inputs of a regression problem after the basis functions have been applied. Each row corresponds to one training example and each column to one basis function. Almost every formula for fitting linear models is written in terms of it.
›What are the normal equations?
They are the set of linear equations that the best weights must satisfy for the sum of squared errors to be as small as possible. Solving them gives the answer in a single step. The name has to do with a geometric property, since the leftover error is perpendicular, or normal, to the space spanned by the basis functions.
›What is the pseudo-inverse?
It generalises the idea of an inverse to tables that are not square, as the design matrix usually isn't, because there are many more data points than basis functions. Multiplying the targets by it gives the best weights. For a square table with an inverse, it simply coincides with the ordinary inverse.
›What does the least-squares solution look like geometrically?
There is an elegant geometric picture in which the targets and the model's possible outputs are points in a space, and the fit is the closest allowed point to the targets.
›What is the maximum likelihood estimate of the noise variance?
It is the average squared gap between the targets and the fitted function, often called the residual variance. It can be computed after the weights, since the best weights do not depend on it. It describes how much scatter remains that the model cannot explain.
›What goes wrong when two basis functions are almost identical?
The data can no longer tell their weights apart, so the equations are nearly degenerate and the solution is unstable. The weights can take huge positive and negative values that nearly cancel. Techniques such as singular value decomposition, or adding a regularisation term, repair the problem. Spotting this early saves a great deal of trouble: very large weights of opposite sign, or results that change dramatically when one data point is removed, are typical warning signs that the basis functions are nearly dependent. Many libraries hide all of this behind a single function call, but the same checks apply to whatever they return.