Dictionary of Applied Machine Learning: 151 machine-learning terms, each with a definition, a figure, citations and a Python demo · All terms · Demos · Start here
Updated on 2026-11-20
Readiness 90/100
See also principal component analysis probabilistic principal component analysis singular value decomposition regularization outlier empirical risk minimization hypothesis space squared error loss
Robust principal component analysis (robust PCA) decomposes a feature matrix into a low-rank matrix, whose rows lie in a subspace of small dimension, and a sparse matrix that carries a few corrupted feature values. Unlike principal component analysis (PCA), it does not compute the low-rank matrix from the recorded values, so a large fault lands in the sparse matrix instead of turning the subspace. One approach states robust PCA as a convex optimization problem, referred to as principal component pursuit. Convex optimization methods solve it, among them the alternating direction method of multipliers (ADMM). The resulting method delivers estimates for the principal directions that span the subspace, and for the corrupted entries in the features of each data point.

rpca.py, which recomputes what the entry states: the script block by block · open in ColabThe weather station Krems an der Donau records the air temperature every hour, so ten days of 2024 give ten rows of $24$ values (Fig. 1). Stacking the $24$ values of one day gives the feature vector ${\mathbf x} \in \mathbb{R}^{d}$, with $d = 24$, of the corresponding data point. Stacking the $m = 10$ feature vectors row-wise gives the $m \times d$ feature matrix ${\mathbf X}$. Each feature vector is centered by subtracting the average of the $m$ feature vectors, so that this average is the zero vector.
Principal component analysis (PCA) uses the feature matrix to learn a given number $d'$ of orthonormal vectors $\mathbf{u}^{(1)}, \ldots, \mathbf{u}^{(d')}$, the principal directions of ${\mathbf X}$. They span a $d'$-dimensional subspace $\mathcal{U}$ of $\mathbb{R}^{d}$ such that each feature vector ${\mathbf x}^{(r)}$, for $r = 1, \ldots, m$, can be well approximated by its projection \[ \mathbf{P} {\mathbf x}^{(r)} = \sum_{j=1}^{d'} \langle \mathbf{u}^{(j)}, {\mathbf x}^{(r)} \rangle \mathbf{u}^{(j)} \text{.}\] Here, $\mathbf{P} \in \mathbb{R}^{d \times d}$ denotes the orthogonal projection matrix on the subspace $\mathcal{U}$. It is given explicitly by $\mathbf{P}=\sum_{j=1}^{d'} \mathbf{u}^{(j)} \big( \mathbf{u}^{(j)} \big)^{\top}$ and provides a fully equivalent representation of the subspace $\mathcal{U}$ spanned by the principal directions.
The projection matrix $\mathbf{P}$ delivered by PCA decomposes each feature vector as ${\mathbf x}^{(r)} = \mathbf{P} {\mathbf x}^{(r)} + {\mathbf e}^{(r)}$, with the approximation error ${\mathbf e}^{(r)}$. These decompositions (one for each $r=1,\ldots,m$) can be expressed more compactly in terms of the feature matrix as \begin{equation} \label{equ_dict_rpca_decomp_pca} {\mathbf X} = {\mathbf L} + \mathbf{E} \text{, where } {\mathbf L} = {\mathbf X} \mathbf{P} \text{ and } \mathbf{E} = {\mathbf X} - {\mathbf L} \text{.} \end{equation} The rank of ${\mathbf L}$ is at most $d'$, since every row of ${\mathbf L}$ lies in the subspace $\mathcal{U}$. The error matrix $\mathbf{E}$ carries the ${\mathbf e}^{(r)}$ as its rows, so $\left\lVert \mathbf{E} \right\rVert_{F}^{2} = \sum_{r=1}^{m} \left\lVert {\mathbf e}^{(r)} \right\rVert_{2}^{2}$. PCA chooses $\mathbf{P}$ to make this quantity as small as possible. In this reading, PCA splits the feature matrix into a low-rank part ${\mathbf L}$ and a small remainder $\mathbf{E}$.
The decomposition \(\eqref{equ_dict_rpca_decomp_pca}\) suggests using a representation of the component $\mathbf{P} {\mathbf x}^{(r)}$ as new features. One such representation is the vector ${\mathbf z}^{(r)} = \big( \langle \mathbf{u}^{(1)}, {\mathbf x}^{(r)} \rangle, \ldots, \langle \mathbf{u}^{(d')}, {\mathbf x}^{(r)} \rangle \big)^{\top}$ whose entries are the inner products between ${\mathbf x}^{(r)}$ and the principal directions of the feature matrix ${\mathbf X}$. For $d' = 2$ the new features $z_{1}, z_{2}$ can be used as coordinates in a scatterplot, as panel (a) of Fig. 2 shows.
B-ten-daysSometimes a feature value is faulty, for example because a temperature sensor fails. The red square in Fig. 1 marks such a failure: the noon reading of day five is increased by $22$ degrees, which gives the perturbed feature vector $\widetilde{{\mathbf x}}^{(5)}$ and, in turn, the perturbed feature matrix $\widetilde{{\mathbf X}}$. Panel (b) of Fig. 2 shows the scatterplot that PCA delivers from $\widetilde{{\mathbf X}}$. The new features $z^{(5)}_{1}, z^{(5)}_{2}$ obtained for $\widetilde{{\mathbf x}}^{(5)}$ are far from those of the other days, and the second learned principal direction turns toward the axis of the perturbed feature. Thus, an isolated but large fault can substantially distort the coordinates of every data point.
B-faultsThe decomposition \(\eqref{equ_dict_rpca_decomp_pca}\) explains why.
Applied to $\widetilde{{\mathbf X}}$, it has the low-rank part
${\mathbf L} = \widetilde{{\mathbf X}} \mathbf{P}$, which is computed from the
recorded values, and a remainder $\mathbf{E}$ that PCA keeps small in the
Frobenius norm. The $22$ degrees can therefore not be left in
$\mathbf{E}$. Most of them have to appear in ${\mathbf L}$, and the only way a
matrix of rank at most $d'$ can carry a large
value at a single entry is for the subspace $\mathcal{U}$ to turn
toward the faulty feature.
The subspace and the principal directions are computed from ${\mathbf L}$ afterwards. The rows of ${\mathbf L}$ span a subspace of dimension at most $d'$, and the principal directions $\mathbf{u}^{(1)}, \ldots, \mathbf{u}^{(d')}$ are the leading right singular vectors of ${\mathbf L}$, delivered by its singular value decomposition (SVD). The projection matrix $\mathbf{P}$ follows from them, and ${\mathbf L} = {\mathbf L} \mathbf{P}$ holds because every row of ${\mathbf L}$ already lies in the subspace that $\mathbf{P}$ projects on. Robust PCA therefore delivers the same objects as PCA, but from a matrix ${\mathbf L}$ that is free of the faulty feature values, since $\mathbf{S}$ carries them.
The goal of making $\mathbf{E}$ small while $\mathbf{S}$ carries only a few non-zero entries can be stated as an optimization problem \begin{equation} \label{equ_dict_rpca_nonconvex} \min_{{\mathbf L}, \mathbf{S} \in \mathbb{R}^{m \times d}} \left\lVert {\mathbf X} - {\mathbf L} - \mathbf{S} \right\rVert_{F} \quad \text{ subject to } \mathop{\mathrm{rank}}({\mathbf L}) \leq d', \; \left\lVert \mathbf{S} \right\rVert_{0} \leq s \text{.} \end{equation} The optimization variables are the two matrices ${\mathbf L}$ and $\mathbf{S}$, and the objective function is the Frobenius norm of the remainder $\mathbf{E} = {\mathbf X} - {\mathbf L} - \mathbf{S}$. The pseudo-norm $\left\lVert \mathbf{S} \right\rVert_{0}$ denotes the number of non-zero entries of $\mathbf{S}$, and $s$ is a given bound on the number of faulty feature values.
The optimization problem \(\eqref{equ_dict_rpca_nonconvex}\) is non-convex, since neither the rank nor the number of non-zero entries is a convex function. Principal component pursuit replaces it with the convex optimization problem \begin{equation} \label{equ_dict_rpca_pcp} \min_{{\mathbf L}, \mathbf{S} \in \mathbb{R}^{m \times d}} \left\lVert {\mathbf L} \right\rVert_{*} + \alpha \left\lVert \mathbf{S} \right\rVert_{1} \quad \text{ subject to } {\mathbf X} = {\mathbf L} + \mathbf{S} \text{,} \end{equation} with a regularization parameter $\alpha > 0$ (Candès et al., 2011). Here, $\left\lVert {\mathbf L} \right\rVert_{*}$ is the sum of the singular values of ${\mathbf L}$, and $\left\lVert \mathbf{S} \right\rVert_{1}$ the sum of the absolute values of the entries of $\mathbf{S}$. These two norms are convex, as every norm is (Boyd and Vandenberghe, 2004, Sects. 3.1.5 and A.1.6), and take the place of the rank of ${\mathbf L}$ and of the number of non-zero entries of $\mathbf{S}$. A large regularization parameter $\alpha$ makes every non-zero entry of $\mathbf{S}$ expensive, so the solution keeps $\mathbf{S}$ sparser and leaves more of ${\mathbf X}$ to ${\mathbf L}$. The rank of ${\mathbf L}$, and with it the dimension $d'$ of the subspace, then comes out larger, while a small $\alpha$ has the opposite effect.
B-pursuitPCA is an instance of empirical risk minimization (ERM) with the squared error loss. Principal component pursuit \(\eqref{equ_dict_rpca_pcp}\) changes its hypothesis space, its criterion, and its optimization method. The hypothesis space is larger: a candidate of PCA is one projection matrix $\mathbf{P}$, which already fixes ${\mathbf L} = {\mathbf X} \mathbf{P}$, whereas a candidate of robust PCA is a pair $({\mathbf L}, \mathbf{S})$, so the sparse matrix is a second unknown. The squared error loss is gone, because the constraint ${\mathbf X} = {\mathbf L} + \mathbf{S}$ leaves no remainder to measure. What principal component pursuit minimizes is therefore not a loss function. It is a convex relaxation of the rank and sparsity constraints of the non-convex optimization problem \(\eqref{equ_dict_rpca_nonconvex}\), and that relaxation is what makes the optimization problem tractable (Candès et al., 2011, Sect. 1.2). The optimization method changes with the criterion: one SVD of the feature matrix suffices for PCA, since its leading right singular vectors are the principal directions (Hastie et al., 2009, Sect. 14.5.1), whereas Algorithm 1 computes one SVD per iteration (Candès et al., 2011, Sect. 5).
B-plotRobust PCA methods differ in the optimization method used to solve
principal component pursuit \(\eqref{equ_dict_rpca_pcp}\).
Algorithm 1 summarizes one such method, obtained by
applying the alternating direction method of multipliers (ADMM). Panel (c) of
Fig. 2 shows the scatterplot that
PCA delivers from the low-rank matrix ${\mathbf L}$ that
Algorithm 1 recovers from the perturbed
feature matrix $\widetilde{{\mathbf X}}$. The ten days are back at
the coordinates of panel (a). The non-zero entries of $\mathbf{S}$ point at
the faulty readings themselves, which is why robust PCA is also
used for anomaly detection.
See also: principal component analysis, sparse principal component analysis, probabilistic principal component analysis, singular value decomposition, rank, alternating direction method of multipliers, proximal operator, fixed-point iteration, least absolute shrinkage and selection operator, regularization, outlier, anomaly detection, robustness, empirical risk minimization, hypothesis space, loss function, squared error loss.
@misc{dictml_rpca,
author = {Jung, Alexander},
editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
title = {robust principal component analysis (robust PCA)},
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-26},
url = {https://dictionaryofml.org/terms/rpca.html}
}