Skip to content

Affine Spaces

Almost everything so far insisted on passing through the origin — subspaces must contain 0\mathbf{0}. But the real world is full of lines and planes that don’t: a regression line with a nonzero intercept, an SVM decision boundary, a GPS position relative to a landmark. These are affine spaces — a subspace that’s been picked up and shifted. This is the bridge from pure linear algebra to the geometry of actual ML models.

A real-life example: a regression line

Fit a line to house prices: price = 50000 + 300 × areaprice = 50000 + 300 × area. The 300 × area300 × area part is a linear (through-the-origin) relationship; the + 50000+ 50000 base price shifts the whole line up so it no longer passes through 0\mathbf{0}. That constant offset is the signature of an affine object. Every model with a bias/intercept term lives in an affine space.

Affine subspaces = support point + direction

Let VV be a vector space, x0V\mathbf{x}_0 \in V a fixed point, and UVU \subseteq V a subspace. The set

L=x0+U={x0+u:uU}L = \mathbf{x}_0 + U = \{\mathbf{x}_0 + \mathbf{u} : \mathbf{u} \in U\}

is an affine subspace (also linear manifold). Here:

  • x0\mathbf{x}_0 is the support point — where the shifted set is “pinned,”
  • UU is the direction space — the subspace that gives LL its orientation.

If x0U\mathbf{x}_0 \notin U, then LL does not contain 0\mathbf{0}, so it is not a subspace. That single shift is the whole difference between linear and affine.

Support point plus direction, live

A line is a support point x0\mathbf{x}_0 (violet) plus all scalar multiples of a direction vector u\mathbf{u} (amber): y=x0+λu\mathbf{y} = \mathbf{x}_0 + \lambda\mathbf{u}. Watch the point y\mathbf{y} slide along the affine line as λ\lambda varies. The grey line through the origin is the underlying direction space UU; the solid line is the affine version, parallel to it but lifted off the origin:

sketch A line as support point + direction p5.js
The violet arrow is the support point x₀. The amber arrow is the direction u. The point y = x₀ + λu (white) slides along the affine line (solid) as λ changes. The dashed grey line is the direction space U through the origin — parallel, but passing through 0.

The affine line and the direction space are parallel — same orientation, different position. The support point is just one way to pin it; any point on the line works equally well.

Lines, planes, and hyperplanes

The parametric equation of a kk-dimensional affine subspace uses a basis (b1,,bk)(\mathbf{b}_1,\dots,\mathbf{b}_k) of its direction space:

x=x0+λ1b1++λkbk.\mathbf{x} = \mathbf{x}_0 + \lambda_1\mathbf{b}_1 + \cdots + \lambda_k\mathbf{b}_k.
  • k=1k = 1 → a line (support point + one direction).
  • k=2k = 2 → a plane (support point + two directions).
  • k=n1k = n-1 in Rn\mathbb{R}^n → a hyperplane — the flat that splits the space into two halves.
diagram Diagram mermaid

A hyperplane is exactly what a linear classifier draws: wx+b=0\mathbf{w}^\top\mathbf{x} + b = 0 separates “class A” from “class B.” The bias bb is what makes it affine rather than forced through the origin.

This ties a bow on the chapter. The solution set of an inhomogeneous system Ax=bA\mathbf{x} = \mathbf{b} (with b0\mathbf{b} \neq \mathbf{0}) is either empty or an affine subspace of dimension nrk(A)n - \text{rk}(A):

{x:Ax=b}=xpsupport point+ker(A)direction space.\{\mathbf{x} : A\mathbf{x} = \mathbf{b}\} = \underbrace{\mathbf{x}_p}_{\text{support point}} + \underbrace{\ker(A)}_{\text{direction space}}.

That’s precisely the “particular solution + null space” decomposition from the solving-systems page — now with a name for its shape. Homogeneous → subspace; inhomogeneous → affine subspace.

Affine mappings

An affine mapping is a linear map followed by a translation:

ϕ(x)=Ax+a,\phi(\mathbf{x}) = A\mathbf{x} + \mathbf{a},

for a linear map AA and a translation vector a\mathbf{a}. Affine maps preserve dimension and parallelism but not the origin. That formula should look familiar — it’s a neural-network layer y=Wx+b\mathbf{y} = W\mathbf{x} + \mathbf{b}, which is affine, not linear, precisely because of the bias b\mathbf{b}.

NumPy: an affine line and a hyperplane

affine.py
import numpy as np
 
# Affine line y = x0 + λ u
x0 = np.array([-1.5, 1.4])     # support point
u  = np.array([1.6, 0.7])      # direction
 
for lam in [-1.0, 0.0, 2.0]:
    print(f"λ={lam:+.0f} -> point {np.round(x0 + lam * u, 2)}")
 
# Does the affine line pass through the origin? (Only if it's really a subspace)
# Solve x0 + λ u = 0  component-wise; consistent only if the λ's agree.
lam_x = -x0[0] / u[0]
lam_y = -x0[1] / u[1]
print("through origin?", np.isclose(lam_x, lam_y))
 
# A hyperplane in R^3: w·x + b = 0  (an affine set, the SVM boundary shape)
w, b = np.array([2.0, -1.0, 3.0]), -4.0
point = np.array([2.0, 0.0, 0.0])
print("on hyperplane?", np.isclose(w @ point + b, 0.0))
affine.py
import numpy as np
 
# Affine line y = x0 + λ u
x0 = np.array([-1.5, 1.4])     # support point
u  = np.array([1.6, 0.7])      # direction
 
for lam in [-1.0, 0.0, 2.0]:
    print(f"λ={lam:+.0f} -> point {np.round(x0 + lam * u, 2)}")
 
# Does the affine line pass through the origin? (Only if it's really a subspace)
# Solve x0 + λ u = 0  component-wise; consistent only if the λ's agree.
lam_x = -x0[0] / u[0]
lam_y = -x0[1] / u[1]
print("through origin?", np.isclose(lam_x, lam_y))
 
# A hyperplane in R^3: w·x + b = 0  (an affine set, the SVM boundary shape)
w, b = np.array([2.0, -1.0, 3.0]), -4.0
point = np.array([2.0, 0.0, 0.0])
print("on hyperplane?", np.isclose(w @ point + b, 0.0))
text
λ=-1 -> point [-3.1  0.7]
λ=+0 -> point [-1.5  1.4]
λ=+2 -> point [1.7 2.8]
through origin? False
on hyperplane? True
text
λ=-1 -> point [-3.1  0.7]
λ=+0 -> point [-1.5  1.4]
λ=+2 -> point [1.7 2.8]
through origin? False
on hyperplane? True

Why this matters for ML

  • Every intercept/bias term (+b+b) makes a model affine, not linear — regression lines, logit boundaries, neural layers.
  • Hyperplanes are decision boundaries: SVMs (Chapter 12) are built entirely on finding a good separating hyperplane wx+b=0\mathbf{w}^\top\mathbf{x} + b = 0.
  • The affine map Wx+bW\mathbf{x} + \mathbf{b} is the literal definition of a dense layer — the reason “affine layer” and “linear layer” are used interchangeably (if loosely) in ML.

🧪 Try It Yourself

Exercise 1 – Points on an affine line

Exercise 2 – Subspace or affine?

Exercise 3 – Which side of the hyperplane?

Recap

  • An affine subspace L=x0+UL = \mathbf{x}_0 + U is a subspace UU shifted by a support point x0\mathbf{x}_0; it’s a subspace only when it contains 0\mathbf{0}.
  • Lines, planes, hyperplanes are affine subspaces of dimension 11, 22, and n1n-1.
  • Inhomogeneous system solutions are affine: particular solution + null space.
  • An affine map is ϕ(x)=Ax+a\phi(\mathbf{x}) = A\mathbf{x} + \mathbf{a} — a linear map plus a shift, exactly a neural-network layer Wx+bW\mathbf{x} + \mathbf{b}.

🎓 Chapter 2 complete

You now have the full linear-algebra toolkit the rest of Mathematics for Machine Learning builds on: systems → matrices → elimination → vector spaces → independence → basis & rank → linear maps → affine spaces. Every neural layer, regression fit, and PCA projection is now something you can read in terms you understand.

Head back to the Linear Algebra Overview to see the whole map again — or revisit any page to replay its visualization.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did