Math for AI course · Lesson 30 of 180

Span: The Predictions a Linear Model Can Reach

Use vector span to identify every prediction a linear model can produce from its feature columns, then detect a target the feature set cannot express.

Share this article

A linear prediction rule can adjust its weights as much as it likes and still miss a pattern its features cannot express. The limit is visible across the training examples: every prediction vector is a weighted sum of the feature columns. Those weighted sums form a set called the span.

By the end of this lesson, you will be able to describe that reachable set, calculate a prediction inside it, and test whether a proposed set of target values could be produced by the model at all.

Learning outcome: Identify the set of vectors reachable by linear combinations.

Lesson 29: Linear independence removes redundancy asks whether feature directions add distinct information. Here we ask the next question: what combinations of those directions can a model actually reach? Section 2.5 of the official Mathematics for Machine Learning book introduces linear combinations and linear independence, the vocabulary needed for this lesson’s definition of span. The prediction example, calculations, code, visual, and assessments here are original.

A model’s outputs live in a reachable set

Suppose a dataset has nn examples and pp numeric features. Put feature jj‘s values for all nn examples into a column vector xj∈Rn\boldsymbol{x}_j\in\mathbb{R}^n. The design matrix X∈Rn×pX\in\mathbb{R}^{n\times p} stacks these columns. For a weight vector w=(w1,…,wp)T∈Rp\boldsymbol{w}=(w_1,\ldots,w_p)^\mathsf{T}\in\mathbb{R}^p, an intercept-free linear model predicts

y^=Xw=w1x1+⋯+wpxp.\hat{\boldsymbol{y}}=X\boldsymbol{w} =w_1\boldsymbol{x}_1+\cdots+w_p\boldsymbol{x}_p.

The matrix-vector product is doing something conceptually important: it mixes the feature columns using the model’s weights. The coefficients can vary, but the only directions available are the columns already in XX.

The last sentence is the capacity claim for this finite dataset: the span contains exactly the prediction vectors the unconstrained linear weights can produce. It does not claim the model can make every possible mapping on future inputs. That depends on the feature rule, its parameters, and what inputs it will see.

Work out the reachable predictions

Consider three examples and two features:

X=[100111],x1=[101],x2=[011].X=\begin{bmatrix} 1&0\\ 0&1\\ 1&1 \end{bmatrix}, \qquad \boldsymbol{x}_1=\begin{bmatrix}1\\0\\1\end{bmatrix}, \quad \boldsymbol{x}_2=\begin{bmatrix}0\\1\\1\end{bmatrix}.

Each weight pair (a,b)(a,b) produces

ax1+bx2=a[101]+b[011]=[aba+b].a\boldsymbol{x}_1+b\boldsymbol{x}_2 =a\begin{bmatrix}1\\0\\1\end{bmatrix} +b\begin{bmatrix}0\\1\\1\end{bmatrix} =\begin{bmatrix}a\\b\\a+b\end{bmatrix}.

So every reachable prediction vector has the form [a,b,a+b]T[a,b,a+b]^\mathsf{T}. Its third coordinate must equal the sum of the first two. This is a plane through zero inside R3\mathbb{R}^3: three output coordinates are recorded, but the two feature directions can only fill that plane.

The failure is a feature limit, not a failure to search long enough for the right coefficients. A model optimizer can choose different weights, but it cannot leave the column span without changing the feature directions or the model form.

Prediction space

Feature columns fence in every prediction

With two feature columns, the model can reach the plane they span. The target vector sits outside because its third value is not the sum of the first two.

Reachable prediction plane and an unreachable targetA plane through the origin is labeled with the rule y three equals y one plus y two. Two solid arrows show feature columns x one and x two on the plane. A dashed arrow marks target y with coordinates one, two, four outside the plane.Col(X): y₃ = y₁ + y₂x₁ = [1, 0, 1]x₂ = [0, 1, 1]target y = [1, 2, 4]zero
The plane represents all vectors [a, b, a + b]. The finite plane patch is only a viewing window; the span continues without bound in every in-plane direction. The dashed target violates the coordinate rule.
Feature combinations and their membership in the column span
VectorCoordinatesSpan check
Feature column x₁[1, 0, 1]Inside: third = first + second
Feature column x₂[0, 1, 1]Inside: third = first + second
Prediction for w = [2, −1][2, −1, 1]Inside: third = first + second
Proposed target[1, 2, 4]Outside: 4 ≠ 1 + 2

The diagram shows the same algebra from the model’s point of view. The solid feature arrows generate the plane, and any weighted combination of them stays there. The dashed target lies off it. The visual makes the location intuitive; the equation y3=y1+y2y_3=y_1+y_2 is the exact test.

Check the limit with a small NumPy calculation

The model computation follows the definition directly. NumPy’s matmul implements the matrix-vector product, so multiplying XX by the weights gives the prediction vector:

import numpy as np

X = np.array([[1, 0], [0, 1], [1, 1]])
weights = np.array([2, -1])
prediction = X @ weights
target = np.array([1, 2, 4])

print(prediction)  # [ 2 -1  1]
print(prediction[2] == prediction[0] + prediction[1])  # True
print(target[2] == target[0] + target[1])  # False

The first line confirms the worked prediction. The second checks the rule that all vectors in this column span must satisfy. The third rejects the proposed target using the same exact relation. This is a structural check; it does not depend on how the weights were trained.

This view also explains a familiar linear-regression constraint. The scikit-learn linear-model guide defines a prediction as a weighted sum of features, with an optional intercept. The fit procedure may try to reduce errors, but on the examples in this lesson an intercept-free model still has only the predictions in Col⁡(X)\operatorname{Col}(X). If every feature column is redundant, the span may not grow when a new feature is added; if a new column points in a genuinely new direction, it can enlarge the reachable set.

Span is about the available directions

The span includes every real coefficient value, including zero and negative weights. That matters: considering only positive combinations would describe a smaller set, often a cone, rather than the full span. Standard unconstrained linear regression permits positive or negative coefficients. Constraints can limit which coefficients are allowed, while regularization changes which weights a training objective prefers; neither changes the column span defined by the feature matrix itself.

The number of feature columns alone does not tell us how many independent directions they provide. Two columns may point along the same line, in which case their span is still one-dimensional. The next step is to determine when a new vector adds an independent direction and can expand the span. That is the question addressed by Lesson 29: linear independence removes redundancy.

The practical habit is simple: when a model repeatedly misses a pattern, ask whether its features can express the needed output before blaming the optimizer. The span tells you which prediction vectors are even on the table.

Check your understanding

Question 1

In your own words, what does the span of two feature columns contain?

Show the step-by-step solution

The span contains every vector formed by multiplying the first feature column by any real number, multiplying the second by any real number, and adding the results. The coefficients can be zero or negative as well as positive, so the set includes all directions generated by those two columns, not only points between them.

Question 2

Let x₁ = [1, 0, 1]ᵀ and x₂ = [0, 1, 1]ᵀ. Compute 3x₁ − 2x₂ and check whether the result follows the span's coordinate rule.

Show the step-by-step solution

Scale each vector first: 3x1=[3,0,3]T3\boldsymbol{x}_1=[3,0,3]^\mathsf{T} and −2x2=[0,−2,−2]T-2\boldsymbol{x}_2=[0,-2,-2]^\mathsf{T}. Add the coordinates to get [3,−2,1]T[3,-2,1]^\mathsf{T}. Its third entry is 11, and the first two sum to 3+(−2)=13+(-2)=1, so it follows the rule and lies in the span.

Question 3

For the matrix with columns [1, 0, 1]ᵀ and [0, 1, 1]ᵀ, write the general prediction vector for weights [a, b]ᵀ.

Show the step-by-step solution

Multiply the first column by aa to get [a,0,a]T[a,0,a]^\mathsf{T}. Multiply the second by bb to get [0,b,b]T[0,b,b]^\mathsf{T}. Their sum is [a,b,a+b]T[a,b,a+b]^\mathsf{T}. Therefore every prediction has third coordinate equal to the sum of its first two coordinates.

Question 4

Can this two-feature model produce [2, 1, 4]ᵀ? Show a decisive test.

Show the step-by-step solution

If the first two coordinates are 22 and 11, then the span rule forces the third coordinate to be 2+1=32+1=3. The proposed third coordinate is 44. Because 4≠34\ne3, no choice of the two weights can produce this vector.

Question 5

Suppose a third feature column is [0, 0, 1]ᵀ. Give weights that produce [1, 2, 4]ᵀ using all three columns.

Show the step-by-step solution

Use weights 11 on [1,0,1]T[1,0,1]^\mathsf{T}, 22 on [0,1,1]T[0,1,1]^\mathsf{T}, and 11 on [0,0,1]T[0,0,1]^\mathsf{T}. The first two weighted columns add to [1,2,3]T[1,2,3]^\mathsf{T}. Adding the third gives [1,2,4]T[1,2,4]^\mathsf{T}, so the new feature supplies exactly the previously missing direction for this target.

Question 6

Does the column span describe every function the trained model could compute for any future input? Explain the scope of the claim.

Show the step-by-step solution

No. The column span here describes prediction vectors across the fixed rows used to construct XX, under the stated intercept-free linear model and unconstrained real weights. Predictions on new inputs depend on their feature values. Changing the feature map or adding nonlinear operations can also change the family of functions the model represents.

Question 7

For these three sample rows, what happens to the span if an intercept column [1, 1, 1]ᵀ is added? Why can it reach [1, 2, 4]ᵀ afterward?

Show the step-by-step solution

The intercept column is not a linear combination of the original two columns: the original span requires the third entry to equal the first plus the second, while [1,1,1]T[1,1,1]^\mathsf{T} does not satisfy 1=1+11=1+1. The new column adds a third independent direction in R3\mathbb{R}^3, so the augmented columns span all of R3\mathbb{R}^3. In particular, [1,2,4]T=2x1+3x2−1[1,2,4]^\mathsf{T}=2\boldsymbol{x}_1+3\boldsymbol{x}_2-\boldsymbol{1}.

Question 8

A model has four feature columns, but two are exact copies of the first two. Does it necessarily gain four independent prediction directions? Explain using span.

Show the step-by-step solution

No. Repeating an existing column does not create a new direction. Any combination of a duplicated column can be absorbed into the coefficient of its copy, so the span stays the same as the span of the original two directions. The number of columns counts available coefficient slots; the span reveals which output directions those slots can collectively reach.

Sources

  1. Mathematics for Machine Learning companion website
  2. Mathematics for Machine Learning book PDF
  3. NumPy documentation: numpy.matmul
  4. scikit-learn documentation: Linear Models