composition.NMF — Scikit-learn 1.1.1 Documentation

Skip to main content Back to top Ctrl+K
  • Install
  • User Guide
  • API
  • Examples
  • Community
  • Getting Started
  • Release History
  • Glossary
  • Development
  • FAQ
  • Support
  • Related Projects
  • Roadmap
  • Governance
  • About us
  • GitHub
Choose version

Section Navigation

  • sklearn
    • config_context
    • get_config
    • set_config
    • show_versions
  • sklearn.base
    • BaseEstimator
    • BiclusterMixin
    • ClassNamePrefixFeaturesOutMixin
    • ClassifierMixin
    • ClusterMixin
    • DensityMixin
    • MetaEstimatorMixin
    • OneToOneFeatureMixin
    • OutlierMixin
    • RegressorMixin
    • TransformerMixin
    • clone
    • is_classifier
    • is_clusterer
    • is_regressor
    • is_outlier_detector
  • sklearn.calibration
    • CalibratedClassifierCV
    • calibration_curve
    • CalibrationDisplay
  • sklearn.cluster
    • AffinityPropagation
    • AgglomerativeClustering
    • Birch
    • BisectingKMeans
    • DBSCAN
    • FeatureAgglomeration
    • HDBSCAN
    • KMeans
    • MeanShift
    • MiniBatchKMeans
    • OPTICS
    • SpectralBiclustering
    • SpectralClustering
    • SpectralCoclustering
    • affinity_propagation
    • cluster_optics_dbscan
    • cluster_optics_xi
    • compute_optics_graph
    • dbscan
    • estimate_bandwidth
    • k_means
    • kmeans_plusplus
    • mean_shift
    • spectral_clustering
    • ward_tree
  • sklearn.compose
    • ColumnTransformer
    • TransformedTargetRegressor
    • make_column_selector
    • make_column_transformer
  • sklearn.covariance
    • EllipticEnvelope
    • EmpiricalCovariance
    • GraphicalLasso
    • GraphicalLassoCV
    • LedoitWolf
    • MinCovDet
    • OAS
    • ShrunkCovariance
    • empirical_covariance
    • graphical_lasso
    • ledoit_wolf
    • ledoit_wolf_shrinkage
    • oas
    • shrunk_covariance
  • sklearn.cross_decomposition
    • CCA
    • PLSCanonical
    • PLSRegression
    • PLSSVD
  • sklearn.datasets
    • clear_data_home
    • dump_svmlight_file
    • fetch_20newsgroups
    • fetch_20newsgroups_vectorized
    • fetch_california_housing
    • fetch_covtype
    • fetch_file
    • fetch_kddcup99
    • fetch_lfw_pairs
    • fetch_lfw_people
    • fetch_olivetti_faces
    • fetch_openml
    • fetch_rcv1
    • fetch_species_distributions
    • get_data_home
    • load_breast_cancer
    • load_diabetes
    • load_digits
    • load_files
    • load_iris
    • load_linnerud
    • load_sample_image
    • load_sample_images
    • load_svmlight_file
    • load_svmlight_files
    • load_wine
    • make_biclusters
    • make_blobs
    • make_checkerboard
    • make_circles
    • make_classification
    • make_friedman1
    • make_friedman2
    • make_friedman3
    • make_gaussian_quantiles
    • make_hastie_10_2
    • make_low_rank_matrix
    • make_moons
    • make_multilabel_classification
    • make_regression
    • make_s_curve
    • make_sparse_coded_signal
    • make_sparse_spd_matrix
    • make_sparse_uncorrelated
    • make_spd_matrix
    • make_swiss_roll
  • sklearn.decomposition
    • DictionaryLearning
    • FactorAnalysis
    • FastICA
    • IncrementalPCA
    • KernelPCA
    • LatentDirichletAllocation
    • MiniBatchDictionaryLearning
    • MiniBatchNMF
    • MiniBatchSparsePCA
    • NMF
    • PCA
    • SparseCoder
    • SparsePCA
    • TruncatedSVD
    • dict_learning
    • dict_learning_online
    • fastica
    • non_negative_factorization
    • sparse_encode
  • sklearn.discriminant_analysis
    • LinearDiscriminantAnalysis
    • QuadraticDiscriminantAnalysis
  • sklearn.dummy
    • DummyClassifier
    • DummyRegressor
  • sklearn.ensemble
    • AdaBoostClassifier
    • AdaBoostRegressor
    • BaggingClassifier
    • BaggingRegressor
    • ExtraTreesClassifier
    • ExtraTreesRegressor
    • GradientBoostingClassifier
    • GradientBoostingRegressor
    • HistGradientBoostingClassifier
    • HistGradientBoostingRegressor
    • IsolationForest
    • RandomForestClassifier
    • RandomForestRegressor
    • RandomTreesEmbedding
    • StackingClassifier
    • StackingRegressor
    • VotingClassifier
    • VotingRegressor
  • sklearn.exceptions
    • ConvergenceWarning
    • DataConversionWarning
    • DataDimensionalityWarning
    • EfficiencyWarning
    • FitFailedWarning
    • InconsistentVersionWarning
    • NotFittedError
    • UndefinedMetricWarning
    • EstimatorCheckFailedWarning
  • sklearn.experimental
    • enable_halving_search_cv
    • enable_iterative_imputer
  • sklearn.feature_extraction
    • DictVectorizer
    • FeatureHasher
    • PatchExtractor
    • extract_patches_2d
    • grid_to_graph
    • img_to_graph
    • reconstruct_from_patches_2d
    • CountVectorizer
    • HashingVectorizer
    • TfidfTransformer
    • TfidfVectorizer
  • sklearn.feature_selection
    • GenericUnivariateSelect
    • RFE
    • RFECV
    • SelectFdr
    • SelectFpr
    • SelectFromModel
    • SelectFwe
    • SelectKBest
    • SelectPercentile
    • SelectorMixin
    • SequentialFeatureSelector
    • VarianceThreshold
    • chi2
    • f_classif
    • f_regression
    • mutual_info_classif
    • mutual_info_regression
    • r_regression
  • sklearn.frozen
    • FrozenEstimator
  • sklearn.gaussian_process
    • GaussianProcessClassifier
    • GaussianProcessRegressor
    • CompoundKernel
    • ConstantKernel
    • DotProduct
    • ExpSineSquared
    • Exponentiation
    • Hyperparameter
    • Kernel
    • Matern
    • PairwiseKernel
    • Product
    • RBF
    • RationalQuadratic
    • Sum
    • WhiteKernel
  • sklearn.impute
    • IterativeImputer
    • KNNImputer
    • MissingIndicator
    • SimpleImputer
  • sklearn.inspection
    • partial_dependence
    • permutation_importance
    • DecisionBoundaryDisplay
    • PartialDependenceDisplay
  • sklearn.isotonic
    • IsotonicRegression
    • check_increasing
    • isotonic_regression
  • sklearn.kernel_approximation
    • AdditiveChi2Sampler
    • Nystroem
    • PolynomialCountSketch
    • RBFSampler
    • SkewedChi2Sampler
  • sklearn.kernel_ridge
    • KernelRidge
  • sklearn.linear_model
    • LogisticRegression
    • LogisticRegressionCV
    • PassiveAggressiveClassifier
    • Perceptron
    • RidgeClassifier
    • RidgeClassifierCV
    • SGDClassifier
    • SGDOneClassSVM
    • LinearRegression
    • Ridge
    • RidgeCV
    • SGDRegressor
    • ElasticNet
    • ElasticNetCV
    • Lars
    • LarsCV
    • Lasso
    • LassoCV
    • LassoLars
    • LassoLarsCV
    • LassoLarsIC
    • OrthogonalMatchingPursuit
    • OrthogonalMatchingPursuitCV
    • ARDRegression
    • BayesianRidge
    • MultiTaskElasticNet
    • MultiTaskElasticNetCV
    • MultiTaskLasso
    • MultiTaskLassoCV
    • HuberRegressor
    • QuantileRegressor
    • RANSACRegressor
    • TheilSenRegressor
    • GammaRegressor
    • PoissonRegressor
    • TweedieRegressor
    • PassiveAggressiveRegressor
    • enet_path
    • lars_path
    • lars_path_gram
    • lasso_path
    • orthogonal_mp
    • orthogonal_mp_gram
    • ridge_regression
  • sklearn.manifold
    • ClassicalMDS
    • Isomap
    • LocallyLinearEmbedding
    • MDS
    • SpectralEmbedding
    • TSNE
    • locally_linear_embedding
    • smacof
    • spectral_embedding
    • trustworthiness
  • sklearn.metrics
    • check_scoring
    • get_scorer
    • get_scorer_names
    • make_scorer
    • accuracy_score
    • auc
    • average_precision_score
    • balanced_accuracy_score
    • brier_score_loss
    • class_likelihood_ratios
    • classification_report
    • cohen_kappa_score
    • confusion_matrix
    • confusion_matrix_at_thresholds
    • d2_brier_score
    • d2_log_loss_score
    • dcg_score
    • det_curve
    • f1_score
    • fbeta_score
    • hamming_loss
    • hinge_loss
    • jaccard_score
    • log_loss
    • matthews_corrcoef
    • multilabel_confusion_matrix
    • ndcg_score
    • precision_recall_curve
    • precision_recall_fscore_support
    • precision_score
    • recall_score
    • roc_auc_score
    • roc_curve
    • top_k_accuracy_score
    • zero_one_loss
    • d2_absolute_error_score
    • d2_pinball_score
    • d2_tweedie_score
    • explained_variance_score
    • max_error
    • mean_absolute_error
    • mean_absolute_percentage_error
    • mean_gamma_deviance
    • mean_pinball_loss
    • mean_poisson_deviance
    • mean_squared_error
    • mean_squared_log_error
    • mean_tweedie_deviance
    • median_absolute_error
    • r2_score
    • root_mean_squared_error
    • root_mean_squared_log_error
    • coverage_error
    • label_ranking_average_precision_score
    • label_ranking_loss
    • adjusted_mutual_info_score
    • adjusted_rand_score
    • calinski_harabasz_score
    • contingency_matrix
    • pair_confusion_matrix
    • completeness_score
    • davies_bouldin_score
    • fowlkes_mallows_score
    • homogeneity_completeness_v_measure
    • homogeneity_score
    • mutual_info_score
    • normalized_mutual_info_score
    • rand_score
    • silhouette_samples
    • silhouette_score
    • v_measure_score
    • consensus_score
    • DistanceMetric
    • additive_chi2_kernel
    • chi2_kernel
    • cosine_distances
    • cosine_similarity
    • distance_metrics
    • euclidean_distances
    • haversine_distances
    • kernel_metrics
    • laplacian_kernel
    • linear_kernel
    • manhattan_distances
    • nan_euclidean_distances
    • paired_cosine_distances
    • paired_distances
    • paired_euclidean_distances
    • paired_manhattan_distances
    • pairwise_kernels
    • polynomial_kernel
    • rbf_kernel
    • sigmoid_kernel
    • pairwise_distances
    • pairwise_distances_argmin
    • pairwise_distances_argmin_min
    • pairwise_distances_chunked
    • ConfusionMatrixDisplay
    • DetCurveDisplay
    • PrecisionRecallDisplay
    • PredictionErrorDisplay
    • RocCurveDisplay
  • sklearn.mixture
    • BayesianGaussianMixture
    • GaussianMixture
  • sklearn.model_selection
    • GroupKFold
    • GroupShuffleSplit
    • KFold
    • LeaveOneGroupOut
    • LeaveOneOut
    • LeavePGroupsOut
    • LeavePOut
    • PredefinedSplit
    • RepeatedKFold
    • RepeatedStratifiedKFold
    • ShuffleSplit
    • StratifiedGroupKFold
    • StratifiedKFold
    • StratifiedShuffleSplit
    • TimeSeriesSplit
    • check_cv
    • train_test_split
    • GridSearchCV
    • HalvingGridSearchCV
    • HalvingRandomSearchCV
    • ParameterGrid
    • ParameterSampler
    • RandomizedSearchCV
    • FixedThresholdClassifier
    • TunedThresholdClassifierCV
    • cross_val_predict
    • cross_val_score
    • cross_validate
    • learning_curve
    • permutation_test_score
    • validation_curve
    • LearningCurveDisplay
    • ValidationCurveDisplay
  • sklearn.multiclass
    • OneVsOneClassifier
    • OneVsRestClassifier
    • OutputCodeClassifier
  • sklearn.multioutput
    • ClassifierChain
    • MultiOutputClassifier
    • MultiOutputRegressor
    • RegressorChain
  • sklearn.naive_bayes
    • BernoulliNB
    • CategoricalNB
    • ComplementNB
    • GaussianNB
    • MultinomialNB
  • sklearn.neighbors
    • BallTree
    • KDTree
    • KNeighborsClassifier
    • KNeighborsRegressor
    • KNeighborsTransformer
    • KernelDensity
    • LocalOutlierFactor
    • NearestCentroid
    • NearestNeighbors
    • NeighborhoodComponentsAnalysis
    • RadiusNeighborsClassifier
    • RadiusNeighborsRegressor
    • RadiusNeighborsTransformer
    • kneighbors_graph
    • radius_neighbors_graph
    • sort_graph_by_row_values
  • sklearn.neural_network
    • BernoulliRBM
    • MLPClassifier
    • MLPRegressor
  • sklearn.pipeline
    • FeatureUnion
    • Pipeline
    • make_pipeline
    • make_union
  • sklearn.preprocessing
    • Binarizer
    • FunctionTransformer
    • KBinsDiscretizer
    • KernelCenterer
    • LabelBinarizer
    • LabelEncoder
    • MaxAbsScaler
    • MinMaxScaler
    • MultiLabelBinarizer
    • Normalizer
    • OneHotEncoder
    • OrdinalEncoder
    • PolynomialFeatures
    • PowerTransformer
    • QuantileTransformer
    • RobustScaler
    • SplineTransformer
    • StandardScaler
    • TargetEncoder
    • add_dummy_feature
    • binarize
    • label_binarize
    • maxabs_scale
    • minmax_scale
    • normalize
    • power_transform
    • quantile_transform
    • robust_scale
    • scale
  • sklearn.random_projection
    • GaussianRandomProjection
    • SparseRandomProjection
    • johnson_lindenstrauss_min_dim
  • sklearn.semi_supervised
    • LabelPropagation
    • LabelSpreading
    • SelfTrainingClassifier
  • sklearn.svm
    • LinearSVC
    • LinearSVR
    • NuSVC
    • NuSVR
    • OneClassSVM
    • SVC
    • SVR
    • l1_min_c
  • sklearn.tree
    • DecisionTreeClassifier
    • DecisionTreeRegressor
    • ExtraTreeClassifier
    • ExtraTreeRegressor
    • export_graphviz
    • export_text
    • plot_tree
  • sklearn.utils
    • Bunch
    • _safe_indexing
    • as_float_array
    • assert_all_finite
    • deprecated
    • estimator_html_repr
    • gen_batches
    • gen_even_slices
    • indexable
    • murmurhash3_32
    • resample
    • safe_mask
    • safe_sqr
    • shuffle
    • Tags
    • InputTags
    • TargetTags
    • ClassifierTags
    • RegressorTags
    • TransformerTags
    • get_tags
    • check_X_y
    • check_array
    • check_consistent_length
    • check_random_state
    • check_scalar
    • check_is_fitted
    • check_memory
    • check_symmetric
    • column_or_1d
    • has_fit_parameter
    • validate_data
    • available_if
    • compute_class_weight
    • compute_sample_weight
    • is_multilabel
    • type_of_target
    • unique_labels
    • density
    • fast_logdet
    • randomized_range_finder
    • randomized_svd
    • safe_sparse_dot
    • weighted_mode
    • incr_mean_variance_axis
    • inplace_column_scale
    • inplace_csr_column_scale
    • inplace_row_scale
    • inplace_swap_column
    • inplace_swap_row
    • mean_variance_axis
    • inplace_csr_row_normalize_l1
    • inplace_csr_row_normalize_l2
    • single_source_shortest_path_length
    • sample_without_replacement
    • min_pos
    • MetadataRequest
    • MetadataRouter
    • MethodMapping
    • get_routing_for_object
    • process_routing
    • all_displays
    • all_estimators
    • all_functions
    • check_estimator
    • parametrize_with_checks
    • estimator_checks_generator
    • Parallel
    • delayed
  • API Reference
  • sklearn.decomposition
  • NMF
NMF# classsklearn.decomposition.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)[source]#

Non-Negative Matrix Factorization (NMF).

Find two non-negative matrices, i.e. matrices with all non-negative elements, (W, H) whose product approximates the non-negative matrix X. This factorization can be used for example for dimensionality reduction, source separation or topic extraction.

The objective function is:

\[ \begin{align}\begin{aligned}L(W, H) &= 0.5 * ||X - WH||_{loss}^2\\ &+ alpha\_W * l1\_ratio * n\_features * ||vec(W)||_1\\ &+ alpha\_H * l1\_ratio * n\_samples * ||vec(H)||_1\\ &+ 0.5 * alpha\_W * (1 - l1\_ratio) * n\_features * ||W||_{Fro}^2\\ &+ 0.5 * alpha\_H * (1 - l1\_ratio) * n\_samples * ||H||_{Fro}^2,\end{aligned}\end{align} \]

where \(||A||_{Fro}^2 = \sum_{i,j} A_{ij}^2\) (Frobenius norm) and \(||vec(A)||_1 = \sum_{i,j} abs(A_{ij})\) (Elementwise L1 norm).

The generic norm \(||X - WH||_{loss}\) may represent the Frobenius norm or another supported beta-divergence loss. The choice between options is controlled by the beta_loss parameter.

The regularization terms are scaled by n_features for W and by n_samples for H to keep their impact balanced with respect to one another and to the data fit term as independent as possible of the size n_samples of the training set.

The objective function is minimized with an alternating minimization of W and H.

Note that the transformed data is named W and the components matrix is named H. In the NMF literature, the naming convention is usually the opposite since the data matrix X is transposed.

Read more in the User Guide.

Parameters: n_componentsint or {‘auto’} or None, default=’auto’

Number of components. If None, all features are kept. If n_components='auto', the number of components is automatically inferred from W or H shapes.

Changed in version 1.4: Added 'auto' value.

Changed in version 1.6: Default value changed from None to 'auto'.

init{‘random’, ‘nndsvd’, ‘nndsvda’, ‘nndsvdar’, ‘custom’}, default=None

Method used to initialize the procedure. Valid options:

  • None: ‘nndsvda’ if n_components <= min(n_samples, n_features), otherwise random.

  • 'random': non-negative random matrices, scaled with: sqrt(X.mean() / n_components)

  • 'nndsvd': Nonnegative Double Singular Value Decomposition (NNDSVD) initialization (better for sparseness)

  • 'nndsvda': NNDSVD with zeros filled with the average of X (better when sparsity is not desired)

  • 'nndsvdar' NNDSVD with zeros filled with small random values (generally faster, less accurate alternative to NNDSVDa for when sparsity is not desired)

  • 'custom': Use custom matrices W and H which must both be provided.

Changed in version 1.1: When init=None and n_components is less than n_samples and n_features defaults to nndsvda instead of nndsvd.

solver{‘cd’, ‘mu’}, default=’cd’

Numerical solver to use:

  • ‘cd’ is a Coordinate Descent solver.

  • ‘mu’ is a Multiplicative Update solver.

Added in version 0.17: Coordinate Descent solver.

Added in version 0.19: Multiplicative Update solver.

beta_lossfloat or {‘frobenius’, ‘kullback-leibler’, ‘itakura-saito’}, default=’frobenius’

Beta divergence to be minimized, measuring the distance between X and the dot product WH. Note that values different from ‘frobenius’ (or 2) and ‘kullback-leibler’ (or 1) lead to significantly slower fits. Note that for beta_loss <= 0 (or ‘itakura-saito’), the input matrix X cannot contain zeros. Used only in ‘mu’ solver.

Added in version 0.19.

tolfloat, default=1e-4

Tolerance of the stopping condition.

max_iterint, default=200

Maximum number of iterations before timing out.

random_stateint, RandomState instance or None, default=None

Used for initialisation (when init == ‘nndsvdar’ or ‘random’), and in Coordinate Descent. Pass an int for reproducible results across multiple function calls. See Glossary.

alpha_Wfloat, default=0.0

Constant that multiplies the regularization terms of W. Set it to zero (default) to have no regularization on W.

Added in version 1.0.

alpha_Hfloat or “same”, default=”same”

Constant that multiplies the regularization terms of H. Set it to zero to have no regularization on H. If “same” (default), it takes the same value as alpha_W.

Added in version 1.0.

l1_ratiofloat, default=0.0

The regularization mixing parameter, with 0 <= l1_ratio <= 1. For l1_ratio = 0 the penalty is an elementwise L2 penalty (aka Frobenius Norm). For l1_ratio = 1 it is an elementwise L1 penalty. For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

Added in version 0.17: Regularization parameter l1_ratio used in the Coordinate Descent solver.

verboseint, default=0

Whether to be verbose.

shufflebool, default=False

If true, randomize the order of coordinates in the CD solver.

Added in version 0.17: shuffle parameter used in the Coordinate Descent solver.

Attributes: components_ndarray of shape (n_components, n_features)

Factorization matrix, sometimes called ‘dictionary’.

n_components_int

The number of components. It is same as the n_components parameter if it was given. Otherwise, it will be same as the number of features.

reconstruction_err_float

Frobenius norm of the matrix difference, or beta-divergence, between the training data X and the reconstructed data WH from the fitted model.

n_iter_int

Actual number of iterations.

n_features_in_int

Number of features seen during fit.

Added in version 0.24.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Defined only when X has feature names that are all strings.

Added in version 1.0.

See also

DictionaryLearning

Find a dictionary that sparsely encodes data.

MiniBatchSparsePCA

Mini-batch Sparse Principal Components Analysis.

PCA

Principal component analysis.

SparseCoder

Find a sparse representation of data from a fixed, precomputed dictionary.

SparsePCA

Sparse Principal Components Analysis.

TruncatedSVD

Dimensionality reduction using truncated SVD.

References

[1]

“Fast local algorithms for large scale nonnegative matrix and tensor factorizations” Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals of electronics, communications and computer sciences 92.3: 708-721, 2009.

[2]

“Algorithms for nonnegative matrix factorization with the beta-divergence” Fevotte, C., & Idier, J. (2011). Neural Computation, 23(9).

Examples

>>> importnumpyasnp >>> X = np.array([[1, 1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]]) >>> fromsklearn.decompositionimport NMF >>> model = NMF(n_components=2, init='random', random_state=0) >>> W = model.fit_transform(X) >>> H = model.components_ fit(X, y=None, **params)[source]#

Learn a NMF model for the data X.

Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the number of features.

yIgnored

Not used, present for API consistency by convention.

**paramskwargs

Parameters (keyword arguments) and values passed to the fit_transform instance.

Returns: selfobject

Returns the instance itself.

fit_transform(X, y=None, W=None, H=None)[source]#

Learn a NMF model for the data X and returns the transformed data.

This is more efficient than calling fit followed by transform.

Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the number of features.

yIgnored

Not used, present for API consistency by convention.

Warray-like of shape (n_samples, n_components), default=None

If init='custom', it is used as initial guess for the solution. If None, uses the initialisation method specified in init.

Harray-like of shape (n_components, n_features), default=None

If init='custom', it is used as initial guess for the solution. If None, uses the initialisation method specified in init.

Returns: Wndarray of shape (n_samples, n_components)

Transformed data.

get_feature_names_out(input_features=None)[source]#

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: ["class_name0", "class_name1", "class_name2"].

Parameters: input_featuresarray-like of str or None, default=None

Only used to validate feature names with the names seen in fit.

Returns: feature_names_outndarray of str objects

Transformed feature names.

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns: routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters: deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns: paramsdict

Parameter names mapped to their values.

inverse_transform(X)[source]#

Transform data back to its original space.

Added in version 0.18.

Parameters: X{ndarray, sparse matrix} of shape (n_samples, n_components)

Transformed data matrix.

Returns: X_originalndarray of shape (n_samples, n_features)

Returns a data matrix of the original shape.

set_output(*, transform=None)[source]#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters: transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • "default": Default output format of a transformer

  • "pandas": DataFrame output

  • "polars": Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: "polars" option was added.

Returns: selfestimator instance

Estimator instance.

set_params(**params)[source]#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters: **paramsdict

Estimator parameters.

Returns: selfestimator instance

Estimator instance.

transform(X)[source]#

Transform the data X according to the fitted NMF model.

Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the number of features.

Returns: Wndarray of shape (n_samples, n_components)

Transformed data.

Gallery examples#

Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation

Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation

Selecting dimensionality reduction with Pipeline and GridSearchCV

Selecting dimensionality reduction with Pipeline and GridSearchCV

Faces dataset decompositions

Faces dataset decompositions On this page
  • NMF
    • fit
    • fit_transform
    • get_feature_names_out
    • get_metadata_routing
    • get_params
    • inverse_transform
    • set_output
    • set_params
    • transform
  • Gallery examples

This Page

  • Show Source

Từ khóa » H No