Math for AI course · Lesson 29 of 180
Linear Independence Removes Redundancy from AI Features
Use a coefficient equation to spot duplicated feature directions, test linear independence by hand, and check a feature matrix with NumPy.
A model can receive two feature columns that look like separate inputs but always rise and fall together. If one column is an exact multiple of the other, the model has been given two names for one direction. The prediction may still be well defined, while the individual weights that produced it are not.
Linear independence gives us a precise test for that redundancy. By the end of this lesson, you will be able to find a nonzero coefficient recipe that adds vectors to zero, explain why that recipe exposes a repeated direction, and check a small AI feature matrix in NumPy.
Lesson 17 introduced linear combinations as weighted sums. Lesson 28 used those combinations to describe restricted features. Section 2.5 of the official Mathematics for Machine Learning uses the same operation to decide whether a collection of vectors contains a redundant direction. The authors’ companion website identifies the linked PDF as the current book download. The feature matrix, worked arithmetic, visual, code, and exercises here are original.
Look for a nonzero recipe that cancels
Suppose we have vectors in one vector space. We ask whether some coefficients can combine them into the zero vector:
The all-zero coefficients always work. The useful question is whether any other choice works.
The zero result alone proves nothing, because setting every coefficient to zero always produces it. Dependence means there is a nontrivial recipe: at least one coefficient is nonzero, yet the weighted directions cancel. One vector in the collection can then be rewritten using the others, so the collection carries a repeated linear direction.
Work the cancellation through
Take two feature directions:
The second vector doubles the first: . Choose coefficients and :
This is a nontrivial relation because the coefficients are not both zero. It also gives a direct rewrite: . Either vector can be removed without changing the set of directions reachable by linear combinations.
The coefficient search below uses and, in its dependent setting, . Move the coefficients to see the scaled vectors add. Switch the second vector to to compare an independent pair. The text result and table repeat the plotted coordinates, so the calculation remains available without interpreting color or shape.
- a u contribution
- b v contribution
- sum a u + b v
| Quantity | Coordinates or value |
|---|---|
| Coefficient a | +1 |
| Coefficient b | -0.5 |
| Vector u | (+1, +2) |
| Vector v | (+2, +4) |
| a u | (+1, +2) |
| b v | (-1, -2) |
| Sum a u + b v | (0, 0) — zero vector |
The sliders search only coefficients from −1 to 1. A plotted cancellation demonstrates dependence; a finite search by itself cannot prove independence.
The independent comparison makes the definition concrete. Let and . If , then
The first coordinate forces . Substituting that into the second gives . Since only the trivial coefficients work, the pair is independent. This algebra is the proof; the interactive grid is a way to explore what different coefficient choices do.
Find repeated feature directions in a model
A design matrix stores examples in rows and features in columns. Suppose a three-example model receives the columns
The columns are dependent because . For a linear model with weights , the predictions are
Only the combined weight affects these predictions. For example, weights and both make that quantity equal to , so both produce . The prediction is the same, but the individual weights are not uniquely determined by these data. This is one concrete way feature redundancy can complicate interpretation.
NumPy’s matrix_rank reports the number of singular values above its tolerance. That gives a practical rank check for floating-point matrices:
import numpy as np
X = np.array([[1., 2.],
[2., 4.],
[3., 6.]])
print(X @ np.array([-2., 1.])) # [0. 0. 0.]
print(np.linalg.matrix_rank(X)) # 1
The first line checks the exhibited relation, while the second reports one independent column direction. The NumPy matrix_rank documentation explains that the calculation uses singular values and a tolerance. Floating point roundoff means an exact zero singular value may appear as a tiny nonzero number, so software applies a threshold.
If two measured columns are almost multiples rather than exact multiples, the mathematical test and a numerical rank decision need care. NumPy notes that its default tolerance can treat sufficiently close columns as rank deficient and that measurement uncertainty may justify a different threshold. For a least-squares fit, the NumPy least-squares documentation also describes rank determination through a singular-value cutoff and returns a minimum-norm solution when multiple solutions minimize the error. A numerical rank is therefore a tolerance-based judgment about the data and computation, not a claim that two measured features are symbolically identical.
The most useful quick checks follow directly from the definition. A zero vector makes a collection dependent. A nonzero scalar multiple duplicates a direction. In , any collection of more than vectors must be dependent because there are only independent directions available. Distinct vectors can still be dependent, as and demonstrate.
For a small exact example, solve the coefficient equation by hand. For a larger data matrix or decimal measurements, inspect its numerical rank and state the tolerance or uncertainty that informed the interpretation. Once independent directions have been identified, the next lesson asks what all their possible linear combinations can express: the span.
Check your understanding
Question 1
In the definition of linear independence, why do we require that only the all-zero coefficients produce the zero vector?
Show the step-by-step solution
All-zero coefficients always give the zero vector, whatever the input vectors are. Independence says there is no second, nontrivial coefficient choice that cancels the vectors; dependence means at least one coefficient is nonzero in such a cancellation.
Question 2
Let u = (1, 3) and v = (2, 6). Give a nontrivial coefficient relation that proves the pair is dependent.
Show the step-by-step solution
Since , choose coefficients and . Then . The coefficients are not both zero, so the pair is dependent.
Question 3
Show that p = (1, 2) and q = (0, 1) are linearly independent.
Show the step-by-step solution
Set . Coordinate by coordinate this is . The first coordinate gives ; then the second gives . Only the trivial coefficient pair works, which is exactly the independence condition.
Question 4
Is the collection containing (0, 0) and (1, 0) independent? Explain using coefficients.
Show the step-by-step solution
It is dependent. Put coefficient on and coefficient on . Their combination equals , and the coefficient pair is nontrivial. A zero vector therefore makes the whole collection dependent.
Question 5
A feature column x₂ is twice x₁. What coefficient relation proves the columns are dependent?
Show the step-by-step solution
The equation rearranges to . The coefficients and are not both zero, so this is a nontrivial zero combination and the columns are dependent.
Question 6
For X = [[1, 2], [2, 4], [3, 6]], what is its rank, and what does that say about its two columns?
Show the step-by-step solution
The second column is twice the first, so the first column supplies one independent direction and the second adds none. The rank is therefore . Equivalently, is a nontrivial coefficient relation.
Question 7
Why must any three vectors in ℝ² be linearly dependent, even if no two of them are equal?
Show the step-by-step solution
has only two independent coordinate directions. A collection of three vectors has more members than the dimension, so at least one vector must be expressible as a linear combination of the others. Equality of two vectors is not required for dependence.
Question 8
NumPy reports a matrix rank using a tolerance. Why might a nearly duplicated feature be treated as redundant even when its values are not exactly a multiple?
Show the step-by-step solution
Floating-point data and measurement noise make exact equality too strict for many practical checks. The matrix-rank calculation counts singular values above a cutoff; if one direction is sufficiently small relative to the chosen tolerance, the matrix is treated as rank deficient. The threshold should reflect numerical precision and, when known, measurement uncertainty.