Two different coefficient vectors can give exactly the same predictions. That happens when a feature column is redundant, and it raises three questions about any linear model. Which prediction vectors can it produce at all, which of them is closest to the targets, and are the coefficients behind that closest prediction determined by the data? This lesson answers the first question with span and column space, the second with orthogonal projection, and the third with linear independence, rank, singular matrices and conditioning.
Key terms
Euclidean norm
Definition On this page uses the ordinary dot product . The Euclidean norm of a vector is
and the Euclidean distance between and is . The norm is zero only for the zero vector. Two vectors are orthogonal when . For nonzero vectors this means they meet at a right angle, and the zero vector is orthogonal to every vector. Orthogonal vectors satisfy the Pythagorean identity
In plain words The norm is the length of an arrow, the Pythagorean theorem applied to all coordinates at once. On this page the vectors hold the target values of observations, so they live in observation space, with one axis per observation, and every coordinate must carry the same unit for a length to make sense. Orthogonality is a statement about dot products, not a claim that observations are statistically independent.
Example Two observations have the targets , both in the same unit. The norm of is . The vectors and are orthogonal, since . The distance from to is the norm of the difference , which is .
Span and column space
Definition The span of vectors in is the set of all their linear combinations with real numbers . The column space of an matrix is the span of its columns,
It is a subspace of , so it contains and is closed under addition and scalar multiplication. The span of one nonzero vector is a line through the origin, and the span of the zero vector is . For a linear model without an intercept, is exactly the set of prediction vectors the model can produce. With an intercept, the same holds for the augmented matrix that includes the ones column.
In plain words The column space collects every prediction vector the model can output as its coefficients range over all real values. A target vector outside it cannot be matched exactly, whatever coefficients are chosen.
Example Take one feature column and no intercept. The predictions fill the line through the origin with slope 2 in observation space. The target is not on that line, because its second coordinate is not twice its first. No coefficient fits both observations exactly.
Orthogonal projection
Definition Let be a subspace of and a vector in . The orthogonal projection of onto is the vector in for which the residual is orthogonal to every vector in . It exists and is unique, and it is the point of closest to . For any in the difference also lies in , so the Pythagorean identity gives
and the second term is zero only when . When is the span of a nonzero vector , the condition gives
The denominator is positive because . On this page the residual is target minus prediction, .
In plain words Drop a perpendicular from the target onto the set of possible predictions. Its foot is the prediction closest to the target in squared Euclidean distance, and what remains has no component along any direction the model allows. If it had one, moving the prediction along that direction would shorten the residual. A projection is a fitted vector, not a claim that the model generated the data.
Example For and , the dot products are and , so . The projection is and the residual is . The check confirms the right angle, and the smallest squared distance is . Any other point of the line does worse. The prediction , from , is at squared distance from , which is the residual term 5 plus .
Linear independence and rank
Definition Vectors are linearly independent if holds only when every , and linearly dependent otherwise. So the columns of are independent exactly when forces . The rank of is the dimension of . It equals the largest number of linearly independent columns and also the largest number of linearly independent rows, so . If , the coefficient vectors that give the same prediction vector are exactly the vectors with . Hence every vector in comes from exactly one coefficient vector when , and from infinitely many when .
In plain words Columns are independent when none of them can be built from the others. The rank counts the independent directions, which can be fewer than the columns. The projection of the targets is always one definite vector, but the coefficients that produce it are unique only when no column is redundant.
Example Add a second column equal to , so that
The column space is still the line spanned by , so the rank is 1 although there are 2 columns. The projection requires , which both and satisfy, along with infinitely many other pairs. The nonzero vector gives , which proves that the columns are dependent. The separate coefficients cannot be identified from these data, although the fitted values are the same.
Singular matrix
Definition A square matrix is singular if it has no inverse. Singularity is equivalent to , to , and to for some nonzero . For an matrix , the matrix is singular exactly when the columns of are dependent, because implies . This matrix appears when the projection condition for is written out. The residual must be orthogonal to every column, , which gives the normal equations
They always have a solution, and every solution gives the projection, . The formula is valid only when is invertible, that is, when .
In plain words A singular matrix sends some nonzero vector to zero, so it loses information and cannot be undone. With redundant features the normal equations still determine the fitted values, but they do not single out one coefficient vector, so a formula that inverts cannot be used. A least-squares solver that handles rank deficiency returns one of the valid solutions by a stated rule, for example the solution with the smallest norm.
Example For the design with the duplicated direction,
The determinant is , so is singular and has no inverse. Both normal equations reduce to , the condition found from the geometry. In NumPy, np.linalg.inv stops with an error on this exact matrix, while np.linalg.lstsq(X, y, rcond=None) returns the smallest-norm solution , which also gives the fitted vector .
Conditioning
Definition Conditioning describes how much the answer to a problem can change when its inputs change slightly. For an invertible square matrix , let and be the largest and smallest values of over nonzero vectors , the most and the least that stretches a vector. The condition number is . If with and , then
A matrix with a large condition number is called ill-conditioned. It is invertible, yet its nearly dependent columns make the solution sensitive. A singular matrix is the limiting case, and its condition number is taken to be infinite. Conditioning belongs to the problem, including the units chosen for the features. Floating-point rounding errors are amplified by it, but they do not cause it.
In plain words Exact dependence means many coefficient vectors fit equally well. Near dependence means exactly one does, but small changes in the targets can move it a lot, so the separate coefficients are hard to interpret even when the fit is good. Stable algorithms avoid adding needless rounding error, but no algorithm can recover information the columns do not contain. Rescaling features, collecting more varied data, dropping a redundant feature or regularization can help, depending on the task.
Example The matrix
has determinant . Its columns differ by , so they are independent and is invertible. For the targets the unique solution of is . Changing the second target to and subtracting the first equation from the second gives , so and . A change of in one target moved each coefficient by . The relative change in is 200 times the relative change in , within the bound set by . Because is square and invertible, both solutions reproduce their targets exactly, so the instability lies only in the coefficients.
Check yourself
- Project onto the span of , with no intercept. Find the coefficient, the projection and the residual, and check that the residual is orthogonal to .
Show the answer
The dot products are and , so and . The residual is , and , so it is orthogonal to .
The smallest squared distance is . By the Pythagorean identity every other point of the line is farther from . For example, the coefficient gives the squared distance , which is .
- Now the feature column is duplicated, so has the two columns and . Which coefficient vectors give the fitted vector ? What is the rank of , and can the coefficients be computed as ?
Show the answer
Here , so the fitted vector is exactly when . Both and work, and so does , along with infinitely many others. The projection itself does not change, because the column space is still the line spanned by .
The rank is 1, not 2. The matrix
has determinant , so it has no inverse and the formula cannot be used. The normal equations, which both read , still describe every valid solution, and the one with the smallest norm is .
- The matrix has determinant , the same as the matrix in the conditioning example. A classmate concludes that it is just as close to singular. Is that right?
Show the answer
No. The matrix shrinks every vector by the same factor , so its largest and smallest stretches are equal and its condition number is 1, the best possible value. Solving gives , and a relative change in produces exactly the same relative change in .
The determinant measures how areas scale, and it changes with units. Multiplying a matrix by a number multiplies its determinant by and leaves its condition number unchanged, so has determinant 1 but still a condition number of about 402. Near singularity is judged by the condition number, not by the size of the determinant.