Dimensionality reduction
Compress non-negative feature matrices into fewer additive dimensions.
Scikit-Learn · Class
NMF factorizes a non-negative matrix X into non-negative matrices W and H whose product approximates X. It is useful for additive representations such as dimensionality reduction, source separation, and topic extraction.
NMF approximates a non-negative input matrix X as the product of two non-negative matrices W and H. It alternately minimizes the objective by updating W and H, with coordinate descent or multiplicative updates controlling the numerical optimization.
NMF(n_components='auto', *, init=None, solver='cd', beta_loss='frobenius', tol=0.0001, max_iter=200, random_state=None, alpha_W=0.0, alpha_H='same', l1_ratio=0.0, verbose=0, shuffle=False, regularization='deprecated')| Name | Type | Description |
|---|---|---|
n_components | int, {'auto'} or None, default='auto' | Number of components; an integer, 'auto', or None. |
solver | {'cd', 'mu'}, default='cd' | Numerical optimization method: coordinate descent or multiplicative updates. |
other parameters | see signature | Initialization and optimization parameters are also accepted by the class; see the official signature for the complete list. |
A fitted NMF estimator; fit_transform additionally returns the transformed matrix W.
import numpy as np
from sklearn.decomposition import NMF
X = np.array([[1, 1], [2, 1], [3, 1], [4, 1]], dtype=float)
model = NMF(n_components=2, init="random", random_state=0)
W = model.fit_transform(X)
H = model.components_
print(W.shape, H.shape)Fits NMF to a non-negative matrix, returning W while exposing H through components_.
Compress non-negative feature matrices into fewer additive dimensions.
Recover additive signals from mixtures represented by non-negative measurements.
Discover additive latent themes in non-negative document-term matrices.
NMF factorizes a non-negative matrix X into non-negative W and H such that WH approximates X. The objective is minimized by alternating updates of W and H.
Follow-up: How do you obtain the factors in scikit-learn? fit_transform returns W, while the fitted model stores H in components_.
NMF is appropriate when the input matrix has no negative values. It can support dimensionality reduction, source separation, and topic extraction.
Follow-up: Why can its representations be interpretable? Components are combined additively, without subtracting one component from another.
The class supports coordinate descent through solver='cd' and multiplicative updates through solver='mu'. Initialization can be random, and the loss can include L1 and L2 regularization priors.
Follow-up: What does transform do after fitting? It decomposes a new matrix using the stored components.
PCATruncatedSVDDictionaryLearningMiniBatchNMF