What is linear algebra in machine learning?
Linear algebra is the mathematics of vectors, matrices, and the linear transformations between them. A vector is an ordered list of numbers, a matrix is a grid of numbers, and multiplying a vector by a matrix maps it to a new vector. The rules are simple and the same in two dimensions or two million.
Machine learning stores almost everything as vectors and matrices: a dataset is a matrix with one row per example, a word embedding is a vector, and a layer's weights are a matrix. Training and inference mostly consist of matrix multiplications, which is why GPUs, built to do many multiply-adds in parallel, made modern deep learning practical. PCA, linear regression, attention, and recommender systems are all linear algebra at their core.
Key ideas
- A vector is an ordered list of numbers that can be read as a point or an arrow.
- Each row of a dataset is a vector, and the whole dataset is a matrix.
- The dot product a · b = |a||b|cos(θ) measures how aligned two vectors are.
- A matrix is a linear transformation, and its columns show where the basis vectors land.
- Each entry of a matrix product is a row-by-column dot product.
- A dense neural network layer is a matrix-vector product followed by a nonlinear activation.
Common questions
How much linear algebra do you need for machine learning?
For applying standard models, vectors, matrices, dot products, matrix multiplication, and transposes cover most needs. Reading research or deriving methods also needs eigenvalues, SVD, matrix calculus, and projections. A course such as Strang's MIT 18.06 covers all of this.
What is the difference between a vector, a matrix, and a tensor?
A vector has one index, a matrix has two, and a tensor is the general name for an array with any number of indices. A batch of RGB images is a 4-dimensional tensor: batch, channels, height, width. Deep learning libraries call every such array a tensor.
What is the transpose of a matrix?
The transpose Aᵀ swaps rows and columns, so entry (i, j) becomes entry (j, i). It turns a column vector into a row vector, which lets the dot product be written as aᵀb. In backpropagation, the gradient flowing back through a layer with weights W is multiplied by Wᵀ.
What does it mean for vectors to be linearly independent?
No vector in the set can be written as a combination of the others. In a dataset, a column that is an exact combination of others, such as a total that equals the sum of two other columns, makes the columns dependent. That makes XᵀX singular and breaks the closed-form solution for linear regression.
Related explainers
- Tensors, Broadcasting & Reshaping — The data structures of deep learning
- Norms & Distance Metrics — L1, L2, cosine similarity — measuring closeness in vector spaces
- Eigenvalues & Eigenvectors — How matrices transform space — eigenvectors, eigenvalues, and decomposition
- Singular Value Decomposition — Factor any matrix into rotation, scaling, and rotation — the Swiss army knife of linear algebra
- Matrix Calculus & Jacobians — Partial derivatives, gradients, and the Jacobian — calculus for vectors
- Neural Networks — Neurons, layers, and how networks learn
References
- Strang, MIT 18.06 Linear Algebra, MIT OpenCourseWare
- Deisenroth, Faisal & Ong, "Mathematics for Machine Learning", ch. 2 Linear Algebra
- Goodfellow, Bengio & Courville, "Deep Learning", ch. 2 Linear Algebra
Last updated