Non-Negative Matrix Factorization
Non-negative matrix factorization breaks a table of only-positive numbers into a small set of building-block parts and the amounts of each part used, with the constraint that nothing is ever subtracted — parts only add up.
Prerequisites: PCA (Principal Component Analysis)
PCA is the standard way to compress a big table of numbers into a few underlying components, but its components are allowed to be negative and to cancel each other out, which makes them mathematically efficient and often humanly unreadable — a "component" that's part positive weight on tech stocks, part negative weight on bonds, doesn't correspond to anything a person would naturally point to. Non-negative matrix factorization (NMF) trades some of that mathematical efficiency for components you can actually interpret as ingredients being added together, never subtracted.
The analogy: recipes, not adjustments
Think of a grocery receipt showing quantities of ingredients bought, and imagine trying to explain many different receipts as combinations of a handful of "typical meals" — a taco-night bundle, a pasta-night bundle, a breakfast bundle. Each receipt is some non-negative amount of each bundle: you can buy 2 taco-nights' worth and 0.5 pasta-nights' worth of ingredients, but you can never buy negative-1 breakfasts to "cancel out" other purchases — that's not how groceries work. NMF finds bundles ("parts") and non-negative amounts of each that reconstruct the original data, respecting the fact that in many real datasets — pixel intensities, word counts, trading volumes — negative amounts are physically meaningless.
The maths: factor into two non-negative pieces
Given a data matrix with rows and columns, all entries non-negative, NMF finds two smaller non-negative matrices (size ) and (size ) such that
In words: each row of (say, one document's word counts, or one day's trading volumes across assets) is approximated as a non-negative combination of "parts" — the rows of are the parts themselves, and the corresponding row of says how much of each part that observation uses. Because nothing is allowed to go negative, the only way to build up a data point is by adding parts together, never by adding a part and then subtracting another to cancel it — which is exactly why NMF parts tend to look like recognisable, additive building blocks rather than PCA's abstract combinations.
Worked example 1: two topics, four documents
Suppose word counts for the words {stock, bond, yield, dividend} across four short documents give . With parts, NMF might discover close to — one part heavy on "stock/dividend," the other heavy on "bond/yield." Then would be close to , meaning documents 1 and 3 are almost entirely made of part 1 ("equity-flavoured"), documents 2 and 4 almost entirely part 2 ("fixed-income-flavoured"). Multiplying row 1 by : , matching the original row exactly — the reconstruction is exact here because the topics happen to be cleanly separated in this toy example.
Worked example 2: why non-negativity forces different answers than PCA
Take a simpler matrix, . PCA's first component here would run along the direction , capturing the shared "overall size" of each row and allowing negative loadings on the second component to capture the vs -style differences. NMF, forbidden from using any negative numbers anywhere, can only express each row as a non-negative sum of two non-negative basis vectors — it can't cancel anything out, so it's forced to represent even the "shared size" and the "difference" as two separate strictly-additive parts, for instance something like part 1 and part 2 , with each row a non-negative blend. The two methods can land on genuinely different decompositions of the identical data, because they're solving differently-constrained problems.
The explorer above shows a matrix reshaping a circle into an ellipse along two directions — NMF's and play an analogous role of finding two "directions" (parts) that reconstruct the data, but constrained to only stretch, never flip through a negative sign.
NMF is typically fit by iteratively rescaling and toward a better fit — a multiplicative update rule whose stability, like the power-law shape shown here, depends on staying strictly on the positive side of zero throughout.
NMF factors non-negative data into non-negative parts and non-negative amounts of each part, forbidding cancellation — which makes it slower and less mathematically clean than PCA but frequently far more interpretable on data where negative values have no real meaning.
What this means in practice
NMF shows up wherever the data is inherently non-negative and additive: decomposing trading volume across venues into a handful of "typical volume profiles," topic modelling in news or filing text, or separating an order book's shape into recurring liquidity patterns. Unlike PCA, NMF's components generally aren't orthogonal and there's no single unique solution — different initialisations of the iterative fitting procedure can converge to different, equally valid factorizations.
The classic mistake is applying NMF to data that isn't actually non-negative, such as raw returns (which are positive and negative), without first transforming it — feeding NMF signed data either breaks the algorithm's assumptions outright or silently produces meaningless parts. Also, don't assume NMF parts are unique the way PCA components are: rerun with a different random initialisation and expect the parts to look different, even if the reconstruction quality is nearly identical.
Related concepts
Practice in interviews
Further reading
- Lee & Seung, Learning the Parts of Objects by Non-negative Matrix Factorization (1999)
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, ch. 14.6