Dictionary of Applied Machine Learning: 114 machine-learning terms, each with a definition, a figure, citations and a Python demo · All terms · Demos · Start here

matrix

Updated on 2026-10-29

Readiness 100/100

▶ Run the Python demo Open in Colab Typeset PDF LaTeX source Markdown Cite this entry

See also dataset feature matrix

A matrix is a two-dimensional array of numbers, arranged in rows and columns. The entry $A_{r,j}$ of a matrix ${\mathbf A} \in \mathbb{R}^{m \times d}$ sits in row $r$ and column $j$. A prominent example in machine learning (ML) is the feature matrix of a dataset, obtained by stacking the feature vectors of $m$ data points row-wise. A matrix represents several distinct mathematical objects. One is a system of linear equations, such as the normal equations of linear regression. Another is a linear map between two vector spaces, after fixing a basis for each. A third is a tabular dataset with one row per data point and one column per feature.

Figure produced by the Python demo of the entry matrix
Figure written by the entry's Python demo matrix.py, which recomputes what the entry states: the script block by block · open in Colab

Definition

P-featuremtxConsider a spreadsheet of daily weather records at one station: each row holds a single day, each column one measurement such as temperature or humidity. Such a tabular dataset holds $m$ data points, each described by the same number $d$ of numerical features. The features of the $r$-th data point are collected in its feature vector ${\mathbf x}^{(r)} = \big(x^{(r)}_{1}, \ldots, x^{(r)}_{d}\big)^{\top} \in \mathbb{R}^{d}$, one entry per column of the spreadsheet. Stacking these $m$ feature vectors row-wise, so that the $r$-th row is $\big({\mathbf x}^{(r)}\big)^{\top}$, produces an $m \times d$ rectangular array of numbers. Its entry in row $r$ and column $j$ is the $j$-th feature of the $r$-th data point. This two-dimensional numeric array is referred to as the feature matrix ${\mathbf X}$ of the dataset; Fig. 1 carries out the construction on three days of the weather example.

Figure 1 of the entry matrix
Figure 1: A tabular dataset of $\samplesize = 3$ data points and the feature matrix built from it. Each row of the table is one day, whose $\nrfeatures = 3$ measurements, temperature (temp.), humidity (humid.), and pressure (press.), form the feature vector $\featurevec^{(\sampleidx)} \in \reals^{3}$; the day column indexes the data points and is not itself a feature, so it does not appear in $\featuremtx$. Stacking $\featurevec^{(1)}, \featurevec^{(2)}, \featurevec^{(3)}$ as rows makes the entry $X_{\sampleidx,\featureidx}$ the $\featureidx$-th measurement taken on day $\sampleidx$: $X_{2,3} = 1008$ is the pressure on day $2$
More generally, a matrix of size $m \times d$ is a two-dimensional array of numbers denoted by \[ {\mathbf A} = \begin{pmatrix} A_{1,1} & A_{1,2} & \dots & A_{1,d} \\ A_{2,1} & A_{2,2} & \dots & A_{2,d} \\ \vdots & \vdots & \ddots & \vdots \\ A_{m,1} & A_{m,2} & \dots & A_{m,d} \end{pmatrix} \in \mathbb{R}^{m \times d}\text{.} \] Here, $A_{r,j}$ denotes the matrix entry in the $r$-th row and the $j$-th column. A digital image is a matrix of exactly this kind. Recording how green each pixel is turns a $16 \times 16$ image into a $16 \times 16$ matrix $\mathbf{G}$ whose two indices are pixel positions (Fig. 2).
Figure 2 of the entry matrix
Figure 2: A $16 \times 16$ pixel image of the "for all" quantifier $\forall$ and the matrix of its green channel. Pixel $(\sampleidx,\featureidx)$ has greenness $G_{\sampleidx, \featureidx} = 1$ where the glyph is drawn and $0$ elsewhere, so the $1$s trace the same shape in $\mG$ that the shaded squares trace in the image
Matrices represent several distinct mathematical objects (Strang, 2016), including the following:
Figure 3 of the entry matrix
Figure 3: The matrix $\mA$ defines a linear map $f^{(\mA)}$ between two vector spaces: the basis vector $\vu^{(\featureidx)}$ is mapped to the vector (thick red arrows) whose coordinates form the $\featureidx$-th column of $\mA$
Written with the feature matrix, the training error that empirical risk minimization (ERM)-based linear regression minimizes becomes a succinct algebraic expression. Collecting the labels of the training set in ${\mathbf y} \in \mathbb{R}^{m}$, the training error of the hypothesis $h^{({\mathbf w})}({\mathbf x}) := {\mathbf w}^{\top}{\mathbf x}$ is \[ (1/m)\,\left\lVert {\mathbf X} {\mathbf w} - {\mathbf y} \right\rVert_{2}^{2} \text{,} \] with gradient $(2/m)\,{\mathbf X}^{\top}({\mathbf X} {\mathbf w} - {\mathbf y})$. Each gradient descent (GD) step is therefore one multiplication by ${\mathbf X}$ followed by one by ${\mathbf X}^{\top}$, and equating the gradient to zero leads back to the normal equations from the first example above.

Matrices appear across machine learning (ML) beyond the feature matrix. The Jacobian matrix and the Hessian collect the first- and second-order partial derivatives of a multivariate function and are the input of gradient-based training. The covariance matrix records the pairwise covariances of a probability distribution over features. Principal component analysis (PCA), singular value decomposition (SVD), and a random projection factor or compress the feature matrix to lower its dimension. A kernel method replaces explicit feature vectors by a matrix of pairwise inner products, and a tabular Markov decision process (MDP) stores its transition probabilities as a matrix. A graph is represented by matrices as well: its adjacency matrix lists which nodes are joined and with what edge weight. The Laplacian matrix assembled from those weights (Luxburg, 2007, Sect. 3) is the matrix whose eigenvectors graph clustering uses to split the nodes into clusters.

See also: linear map, dataset, linear model, vector, feature matrix, normal equations, array, transpose.

References

  1. Strang (2016). Introduction to Linear Algebra. Wellesley-Cambridge Press.
  2. Luxburg (2007). A tutorial on spectral clustering. Statist. Comput.. doi.org/10.1007/s11222-007-9033-z

Cite this entry

@misc{dictml_matrix,
  author = {Jung, Alexander},
  editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {matrix},
  howpublished = {Dictionary of Applied Machine Learning (course edition)},
  year = {2026},
  doi = {10.5281/zenodo.21569296},
  note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-11-04},
  url = {https://dictionaryofml.org/terms/matrix.html}
}