Class: NMF

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:

Python Reference

Constructors

new NMF()

new NMF(opts?): NMF

Parameters

ParameterTypeDescription
opts?object-
opts.alpha_H?number | "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.
opts.alpha_W?numberConstant that multiplies the regularization terms of W. Set it to zero (default) to have no regularization on W.
opts.beta_loss?number | "frobenius" | "kullback-leibler" | "itakura-saito"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.
opts.init?"random" | "nndsvd" | "nndsvda" | "nndsvdar" | "custom"Method used to initialize the procedure. Valid options:
opts.l1_ratio?numberThe 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.
opts.max_iter?numberMaximum number of iterations before timing out.
opts.n_components?number | "auto"Number of components, if n_components is not set all features are kept. If n_components='auto', the number of components is automatically inferred from W or H shapes.
opts.random_state?numberUsed for initialisation (when init == ‘nndsvdar’ or ‘random’), and in Coordinate Descent. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.shuffle?booleanIf true, randomize the order of coordinates in the CD solver.
opts.solver?"cd" | "mu"Numerical solver to use:
opts.tol?numberTolerance of the stopping condition.
opts.verbose?numberWhether to be verbose.

Returns NMF

Defined in generated/decomposition/NMF.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/decomposition/NMF.ts:23
_isInitializedbooleanfalsegenerated/decomposition/NMF.ts:22
_pyPythonBridgeundefinedgenerated/decomposition/NMF.ts:21
idstringundefinedgenerated/decomposition/NMF.ts:18
optsanyundefinedgenerated/decomposition/NMF.ts:19

Accessors

components_

Get Signature

get components_(): Promise<ArrayLike[]>

Factorization matrix, sometimes called ‘dictionary’.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/NMF.ts:437


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

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

Returns Promise<ArrayLike>

Defined in generated/decomposition/NMF.ts:553


n_components_

Get Signature

get n_components_(): Promise<number>

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.

Returns Promise<number>

Defined in generated/decomposition/NMF.ts:460


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/decomposition/NMF.ts:530


n_iter_

Get Signature

get n_iter_(): Promise<number>

Actual number of iterations.

Returns Promise<number>

Defined in generated/decomposition/NMF.ts:508


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/decomposition/NMF.ts:108


reconstruction_err_

Get Signature

get reconstruction_err_(): Promise<number>

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

Returns Promise<number>

Defined in generated/decomposition/NMF.ts:483

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/decomposition/NMF.ts:159


fit()

fit(opts): Promise<any>

Learn a NMF model for the data X.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters (keyword arguments) and values passed to the fit_transform instance.
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/decomposition/NMF.ts:176


fit_transform()

fit_transform(opts): Promise<ArrayLike[]>

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

This is more efficient than calling fit followed by transform.

Parameters

ParameterTypeDescription
optsobject-
opts.H?ArrayLike[]If init='custom', it is used as initial guess for the solution. If undefined, uses the initialisation method specified in init.
opts.W?ArrayLike[]If init='custom', it is used as initial guess for the solution. If undefined, uses the initialisation method specified in init.
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/NMF.ts:219


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

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

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly used to validate feature names with the names seen in fit.

Returns Promise<any>

Defined in generated/decomposition/NMF.ts:268


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/decomposition/NMF.ts:302


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/decomposition/NMF.ts:121


inverse_transform()

inverse_transform(opts): Promise<ArrayLike[]>

Transform data back to its original space.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTransformed data matrix.
opts.Xt?ArrayLikeTransformed data matrix.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/NMF.ts:334


set_output()

set_output(opts): Promise<any>

Set output container.

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

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/decomposition/NMF.ts:373


transform()

transform(opts): Promise<ArrayLike[]>

Transform the data X according to the fitted NMF model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/NMF.ts:405