This course aims to equip students with the mathematical foundations necessary for understanding and applying machine learning models, covering topics such as linear algebra, probability, optimization techniques, and regularization methods.
Unit 1:Unit 1: Linear Algebra Foundations for Machine Learning
22 min read•High-Yield Unit Guide
Unit 1: Linear Algebra Foundations for Machine Learning
Unit 1 Exam Focus & Core Takeaways
Review the core definitions, standard architectures, and syntax patterns below. Pay special attention to sections highlighted with bullet points for your mid-term and end-term subjective questions.
Unit 1: Linear Algebra Foundations for Machine Learning
Linear algebra is the foundational mathematical language of machine learning. From simple linear regression to deep multi-layer neural networks, transformers, and diffusion models, virtually every data point, weight parameter, activation map, and gradient update is expressed as a vector, matrix, or higher-order tensor. Mastering vector spaces, subspaces, matrix operations, inner products, norms, projections, and linear transformations is indispensable for understanding data representation, dimensionality reduction, loss optimization, and feature transformations.
1. Vectors, Matrices, and Tensors in Machine Learning
1.1 Vectors
In machine learning, a vector is an ordered finite collection of scalar numbers representing a single data sample, feature set, or model parameter vector.
Mathematically, an n-dimensional real vector x∈Rn is written by convention as an n×1 column vector: x=x1x2⋮xn
The transpose xT turns it into a 1×n row vector: xT=[x1,x2,…,xn]
Feature Space Interpretation: Each component xi denotes the numeric value of feature i (e.g., house area, number of bedrooms, age of structure). A dataset of m samples each having d features can be envisioned as m vectors inhabiting Rd.
Vector Operations
Vector Addition: For u,v∈Rn, u+v=[u1+v1,u2+v2,…,un+vn]T.
Scalar Multiplication: For c∈R, cu=[cu1,cu2,…,cun]T.
Dot Product (Inner Product): u⋅v=uTv=∑i=1nuivi
Geometric interpretation: u⋅v=∥u∥2∥v∥2cosθ, where θ is the angle between the two vectors. If uTv=0, the vectors are orthogonal.
Hadamard Product (Element-wise Product): u⊙v=[u1v1,u2v2,…,unvn]T
Frequently used in neural network activation gating (e.g., LSTMs and GRUs).
Outer Product:
For u∈Rm and v∈Rn, the outer product produces a rank-1 matrix: uvT∈Rm×n,(uvT)ij=uivj
1.2 Matrices
A matrixA∈Rm×n is a rectangular 2D array of scalars with m rows and n columns: A=a11a21⋮am1a12a22⋮am2⋯⋯⋱⋯a1na2n⋮amn
Design Matrix (X∈RN×d): In supervised and unsupervised learning, tabular datasets are typically organized into a design matrix where row i represents sample xiT and column j corresponds to feature j.
Weight Matrix (W∈Rdout×din): In linear layers and neural networks, linear mappings y=Wx+b map inputs of dimension din to dimension dout.
Matrix Multiplication: For A∈Rm×k and B∈Rk×n, the product C=AB∈Rm×n is given by: Cij=∑p=1kAipBpj
Properties: Associative (A(BC)=(AB)C), Distributive (A(B+C)=AB+AC), but generally non-commutative (AB=BA).
A tensor is a multidimensional array that generalizes scalars (order-0 tensors), vectors (order-1 tensors), and matrices (order-2 tensors) to arbitrary dimensions (orders / ranks / modes):
Order-0: Scalar s∈R (e.g., loss value, learning rate).
Order-1: Vector x∈Rd (e.g., word embedding, feature vector).
A vector space(V,+,⋅) over a scalar field R is a set of elements (vectors) endowed with two operations: vector addition (+:V×V→V) and scalar multiplication (⋅:R×V→V) satisfying the following eight axioms for all u,v,w∈V and α,β∈R:
Associativity of Addition:u+(v+w)=(u+v)+w
Commutativity of Addition:u+v=v+u
Additive Identity: There exists 0∈V such that u+0=u.
Additive Inverse: For every u∈V, there exists −u∈V such that u+(−u)=0.
Compatibility of Scalar Multiplication:α(βu)=(αβ)u
Scalar Multiplicative Identity:1⋅u=u
Distributivity over Vector Addition:α(u+v)=αu+αv
Distributivity over Scalar Addition:(α+β)u=αu+βu
2.2 Linear Independence, Span, and Basis
Linear Combination: Given a set of vectors {v1,v2,…,vk}⊂V, a linear combination is: w=∑i=1kcivi,ci∈R
Linear Span: The set of all possible linear combinations of {v1,…,vk}: span(v1,…,vk)={∑i=1kcivici∈R}
Linear Independence: A set of vectors {v1,…,vk} is linearly independent if and only if the vector equation: c1v1+c2v2+⋯+ckvk=0
holds only when c1=c2=⋯=ck=0. If non-zero coefficients exist satisfying the equation, the vectors are linearly dependent (i.e., at least one vector can be expressed as a linear combination of the others).
Basis: A subset B={b1,…,bn} of a vector space V is a basis if:
B is linearly independent.
span(B)=V.
Every vector v∈V has a unique representation in terms of basis B.
Dimension: The number of vectors in any basis of V is called the dimension of V, denoted dim(V). For Rn, dim(Rn)=n.
Standard Basis: In Rn, the standard canonical basis is {e1,…,en} where ei has 1 at index i and 0 elsewhere.
2.3 Subspaces and Fundamental Subspaces of a Matrix
A subset S⊆V is a subspace of V if and only if:
0∈S (contains the zero vector).
For all u,v∈S, u+v∈S (closed under addition).
For all c∈R and u∈S, cu∈S (closed under scalar multiplication).
For any matrix A∈Rm×n, there are four fundamental subspaces:
Column Space (Range) C(A)⊆Rm: C(A)={Ax∣x∈Rn}=span(columns of A)
Its dimension is the column rank of A. In linear regression y^=Xw, the model predictions y^ must lie within the column space of X.
Null Space (Kernel) N(A)⊆Rn: N(A)={x∈Rn∣Ax=0}
Its dimension is the nullity of A.
Row Space C(AT)⊆Rn: C(AT)={ATy∣y∈Rm}=span(rows of A)
Row rank equals column rank, known simply as the rank of A, denoted rank(A).
Left Null Space N(AT)⊆Rm: N(AT)={y∈Rm∣ATy=0}
The Rank-Nullity Theorem (Fundamental Theorem of Linear Algebra)
For any matrix A∈Rm×n: rank(A)+nullity(A)=n
Furthermore, C(AT)⊥N(A) in Rn (they are orthogonal complements: Rn=C(AT)⊕N(A)), and C(A)⊥N(AT) in Rm.
3. Norms and Projections
3.1 Vector Norms
A norm on a vector space V is a function ∥⋅∥:V→R≥0 that assigns a non-negative length or magnitude to each vector, satisfying three core axioms:
Non-negativity & Definiteness:∥x∥≥0, and ∥x∥=0⟺x=0.
Frobenius Norm: Measures the overall magnitude of matrix entries, analogous to the Euclidean norm of vectorized matrix: ∥A∥F=∑i=1m∑j=1nAij2=Tr(ATA)
Spectral Norm (Induced 2-Norm): ∥A∥2=maxx=0∥x∥2∥Ax∥2=σmax(A)
where σmax(A) is the largest singular value of A. Critical in spectral normalization for GAN stability.
3.3 Orthogonality and Projections
Two vectors u,v∈Rn are orthogonal (u⊥v) if their inner product is zero: uTv=0
If in addition ∥u∥2=∥v∥2=1, they are orthonormal.
Projection of a Vector onto Another Vector
The orthogonal projection of vector y onto a non-zero vector x is: projx(y)=xTxxTyx=∥x∥22xTyx
The residual vector e=y−projx(y) is orthogonal to x: xTe=0.
Projection onto a Subspace and Linear Regression
Let S=C(A) be the subspace spanned by the linearly independent columns of A∈Rm×d (m>d).
To project an arbitrary target vector y∈Rm orthogonally onto C(A), we seek y^=Aw^∈C(A) minimizing ∥y−y^∥22.
The orthogonality condition requires the error residual e=y−Aw^ to be orthogonal to every column of A: AT(y−Aw^)=0⟹ATAw^=ATy
This is the celebrated Normal Equation of Ordinary Least Squares (OLS) regression!
When A has full column rank, ATA is invertible: w^=(ATA)−1ATy
The projection y^ is given by: y^=Aw^=A(ATA)−1ATy=Py
where P=A(ATA)−1AT is the orthogonal projection matrix (Hat Matrix H).
Properties of a projection matrix P:
Idempotence:P2=P (projecting twice gives the exact same result).
Symmetry:PT=P (for orthogonal projections).
Eigenvalues: All eigenvalues of an orthogonal projection matrix are either 0 or 1.
4. Linear Operators and Transformations in ML
4.1 Linear Transformations
A mapping T:V→W between two vector spaces is a linear transformation (or linear map) if and only if it preserves vector addition and scalar multiplication:
T(u+v)=T(u)+T(v) for all u,v∈V.
T(cu)=cT(u) for all c∈R,u∈V.
Together: T(αu+βv)=αT(u)+βT(v).
4.2 Matrix Representation of Linear Transformations
Every linear transformation T:Rn→Rm can be represented uniquely as multiplication by an m×n matrix A: T(x)=Ax
The j-th column of A is simply the transformation of the j-th standard basis vector: A:,j=T(ej)
Geometric Interpretations of Elementary Transformations in R2
Rotation by angle θ: R(θ)=[cosθsinθ−sinθcosθ],det(R)=1
Scaling by factors sx,sy: S=[sx00sy],det(S)=sxsy
Shearing along x-axis: [10k1],det=1
Reflection across x-axis: [100−1],det=−1
4.3 Change of Basis
Suppose we have a vector x expressed in the standard basis. If we introduce a new basis B={b1,…,bn}, we form the change-of-basis matrix P=[b1…bn].
Coordinate transformation: x=P[x]B⟹[x]B=P−1x.
Transformation representation in new basis: If a linear transformation is given by matrix A in standard coordinates, its matrix representation in basis B is: [T]B=P−1AP
Matrices A and B=P−1AP are said to be similar matrices. They share identical eigenvalues, trace, and determinant.
4.4 Affine Transformations vs Linear Transformations
A linear transformation must always map the origin to the origin: T(0)=0.
In deep learning layers: y=Wx+b
Because of the bias vector b=0, this map does not preserve the origin (T(0)=b=0). It is therefore not strictly linear, but an affine transformation (a linear transformation followed by a translation).
Using homogeneous coordinates, an affine transformation can be represented as a linear transformation in Rn+1: [y1]=[W0Tb1][x1]
5. Comparative Summary & Formula Cheatsheet
Concept
Mathematical Expression
Key Properties / Invariants
Dot Product
uTv=∑i=1nuivi
uTv=∥u∥2∥v∥2cosθ; commutative
Orthogonality
uTv=0
Angle θ=90∘; Pythagoras: ∥u+v∥22=∥u∥22+∥v∥22
L1 Norm
∑i=1n∥xi∥
Sparsity inducing, robust to outliers, non-differentiable at 0
Measures volume scaling; det(A)=0⟺A is invertible
6. Common Pitfalls and Exam Traps
Confusing Linearity with Affine mappings: In machine learning, f(x)=Wx+b is colloquially called a "linear layer", but mathematically it is strictly an affine transformation unless the bias b=0.
Order of Matrix Multiplication:AB=BA. Furthermore, (AB)T=BTAT and (AB)−1=B−1A−1 (order reverses!).
Idempotence Property: Remember that any projection matrix satisfies P2=P. Consequently, Pk=P for all positive integers k.
Rank of Outer Product: The outer product of two non-zero vectors uvT always produces a matrix of rank exactly 1, regardless of the dimensions of u and v.
Invertibility of ATA:ATA is invertible if and only if the columns of A are linearly independent (i.e., A has full column rank). If features are multicollinear, ATA becomes singular.