Non-negative matrix factorization (NMF, also NNMF) is an unsupervised machine learning method that approximates a non-negative data matrix V as the product of two smaller non-negative matrices, W and H, so that V is approximately W times H. Because no entry may be negative, every data point is reconstructed as an additive combination of parts, which makes the learned components unusually easy to interpret.
NMF became widely known after Lee and Seung showed in 1999 that it learns parts-based representations of faces and text. In machine learning it is used for dimensionality reduction, topic modeling, audio source separation, recommender systems and the analysis of gene expression, spectra and other measurements that are naturally non-negative.
How NMF decomposes a data matrix
Given a matrix V of size m by n, for example m words by n documents, NMF chooses a rank k much smaller than m and n and finds W of size m by k and H of size k by n. Each column of W is a basis component, such as a topic or a spectral pattern, and each column of H holds the non-negative weights that say how much of each component a given sample contains.
The factors are found by minimizing a reconstruction error between V and WH subject to the non-negativity constraints. The problem is non-convex in W and H jointly, so algorithms find a local minimum and the result depends on initialization. Unlike singular value decomposition, NMF has no closed-form solution and its components are not ordered by importance or mutually orthogonal.
The table below describes the objects involved in a factorization.
| Element | Shape | Meaning | Constraint |
|---|---|---|---|
| V (data matrix) | m by n | Observed non-negative data | All entries zero or positive |
| W (basis matrix) | m by k | Components, parts or topics | Non-negative |
| H (coefficient matrix) | k by n | Activation of each component per sample | Non-negative |
| k (rank) | Scalar | Number of components | Usually much smaller than m and n |
Objective functions and algorithms
The choice of loss function should match the noise model of the data. The Frobenius norm assumes Gaussian noise and suits continuous measurements, the generalized Kullback-Leibler divergence corresponds to Poisson counts such as word frequencies, and the Itakura-Saito divergence is scale-invariant and popular for audio power spectrograms. All three belong to the broader beta-divergence family.
| Loss | Implied noise model | Typical data |
|---|---|---|
| Frobenius norm | Gaussian | Images, continuous signals |
| Kullback-Leibler divergence | Poisson | Word counts, event counts |
| Itakura-Saito divergence | Multiplicative gamma | Audio power spectra |
Classic multiplicative update rules rescale each entry of W and H by a ratio of positive terms, which keeps factors non-negative automatically and is simple to implement, but convergence can be slow. Alternating non-negative least squares and coordinate descent usually converge faster and are the default in modern libraries. Initialization with NNDSVD, a non-negative variant of singular value decomposition, gives more stable and reproducible results than random starting points.
Computational cost per iteration is roughly proportional to m times n times k for dense data and to the number of non-zero entries times k for sparse data. Large corpora are therefore handled with sparse matrix storage, mini-batch or online NMF variants that update factors from chunks of samples, and GPU implementations. A common stopping rule halts training once the relative change in loss falls below about 0.0001, although a fixed iteration budget is also widely used.
NMF compared with PCA and related methods
NMF is often contrasted with principal component analysis and other matrix factorizations because all of them compress data into a small number of latent factors. The comparison below shows where NMF differs in practice.
| Method | Sign constraints | Component structure | Interpretability |
|---|---|---|---|
| NMF | Non-negative factors | Additive, often sparse parts | High for non-negative data |
| PCA / SVD | None | Orthogonal, ordered by variance | Lower, components mix signs |
| Independent component analysis | None | Statistically independent sources | Moderate |
| Latent Dirichlet allocation | Probabilistic, non-negative | Topic distributions | High, with uncertainty estimates |
| k-means clustering | Hard assignments | One centroid per sample | High but coarse |
With KL divergence, NMF is mathematically closely related to probabilistic latent semantic analysis, and with orthogonality constraints on H it behaves like a soft form of k-means clustering. These links explain why NMF topics and clusters often resemble those of probabilistic models.
Choosing the rank and preparing data
The rank k is the most consequential hyperparameter. A low rank merges distinct patterns, whereas a high rank splits them into redundant or noisy components. Practitioners compare reconstruction error curves, cross-validated error on masked entries, topic coherence for text and the stability of components across random restarts.
Preprocessing matters as much as the algorithm. Text is usually weighted with TF-IDF and normalized, spectra are kept on a magnitude or power scale, and very sparse rows or columns are removed. Regularization with L1 penalties produces sparser components, while L2 penalties stabilize solutions on noisy data.
| Data type | Recommended loss | Typical rank | Preprocessing |
|---|---|---|---|
| Document-term matrix | Frobenius on TF-IDF or KL on counts | 10-100 | Stop word removal, normalization |
| Audio spectrogram | Itakura-Saito or KL | 5-50 | Magnitude or power scale |
| Gene expression | Frobenius or KL | 2-20 | Filtering low-variance genes |
| User-item ratings | Frobenius on observed entries | 10-200 | Masking missing values |
Limitations and common mistakes
- Non-uniqueness: different runs can yield different factorizations with similar error, so components should be checked for stability.
- Scale ambiguity: W can be multiplied and H divided by the same diagonal matrix, so normalize columns before comparing components.
- Negative inputs: centered or standardized data violate the model; shift or transform the data instead of clipping values.
- Treating zeros as missing: in recommender data, unobserved entries must be masked rather than fitted as true zeros.
- Over-reading components: interpretable parts are a tendency, not a guarantee, and require domain validation.
The idea in brief
Non-negative matrix factorization takes a large table of positive numbers and explains it with a few building blocks. Think of a smoothie. NMF guesses the ingredients and how much of each went in.
Because nothing can be subtracted, every item is a sum of parts. That is why the parts often make sense to people. A pile of articles becomes a short list of themes, and each article becomes a mix of those themes.
A practical scenario
A customer support team at a software company receives about 40,000 tickets a month and wants to know what customers complain about without reading every message. An analyst builds a TF-IDF document-term matrix with 15,000 terms and runs NMF with NNDSVD initialization, testing ranks from 10 to 40.
Topic coherence and stability across restarts peak at rank 22. The components map cleanly to themes such as login failures, invoice errors and slow exports, and the H matrix gives each ticket a weighted theme profile. Monthly tracking of these weights reveals that export complaints doubled after a release, which leads engineers to a performance regression that is fixed in the next update.