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 (opens in a new tab)
Constructors
constructor()
Signature
new NMF(opts?: object): NMF;
Parameters
Name | Type | Description |
---|---|---|
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 . Default Value 'same' |
opts.alpha_W? | number | Constant that multiplies the regularization terms of W . Set it to zero (default) to have no regularization on W . Default Value 0 |
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. Default Value 'frobenius' |
opts.init? | "random" | "nndsvd" | "nndsvda" | "nndsvdar" | "custom" | Method used to initialize the procedure. Valid options: |
opts.l1_ratio? | number | 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. Default Value 0 |
opts.max_iter? | number | Maximum number of iterations before timing out. Default Value 200 |
opts.n_components? | number | Number of components, if n_components is not set all features are kept. |
opts.random_state? | number | Used 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? | boolean | If true, randomize the order of coordinates in the CD solver. Default Value false |
opts.solver? | "cd" | "mu" | Numerical solver to use: Default Value 'cd' |
opts.tol? | number | Tolerance of the stopping condition. Default Value 0.0001 |
opts.verbose? | number | Whether to be verbose. Default Value 0 |
Returns
Defined in: generated/decomposition/NMF.ts:25 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/decomposition/NMF.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/decomposition/NMF.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/decomposition/NMF.ts:21 (opens in a new tab)
id
string
Defined in: generated/decomposition/NMF.ts:18 (opens in a new tab)
opts
any
Defined in: generated/decomposition/NMF.ts:19 (opens in a new tab)
Accessors
components_
Factorization matrix, sometimes called ‘dictionary’.
Signature
components_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/decomposition/NMF.ts:423 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/decomposition/NMF.ts:539 (opens in a new tab)
n_components_
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.
Signature
n_components_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/decomposition/NMF.ts:446 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/decomposition/NMF.ts:516 (opens in a new tab)
n_iter_
Actual number of iterations.
Signature
n_iter_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/decomposition/NMF.ts:494 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/decomposition/NMF.ts:108 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/decomposition/NMF.ts:112 (opens in a new tab)
reconstruction_err_
Frobenius norm of the matrix difference, or beta-divergence, between the training data X
and the reconstructed data WH
from the fitted model.
Signature
reconstruction_err_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/decomposition/NMF.ts:469 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/decomposition/NMF.ts:170 (opens in a new tab)
fit()
Learn a NMF model for the data X.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vector, where n\_samples is the number of samples and n\_features is the number of features. |
opts.params? | any | Parameters (keyword arguments) and values passed to the fit_transform instance. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<any
>
Defined in: generated/decomposition/NMF.ts:187 (opens in a new tab)
fit_transform()
Learn a NMF model for the data X and returns the transformed data.
This is more efficient than calling fit followed by transform.
Signature
fit_transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.H? | ArrayLike [] | If init=’custom’, it is used as initial guess for the solution. |
opts.W? | ArrayLike [] | If init=’custom’, it is used as initial guess for the solution. |
opts.X? | ArrayLike | Training vector, where n\_samples is the number of samples and n\_features is the number of features. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/decomposition/NMF.ts:233 (opens in a new tab)
get_feature_names_out()
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"\]
.
Signature
get_feature_names_out(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.input_features? | any | Only used to validate feature names with the names seen in fit . |
Returns
Promise
<any
>
Defined in: generated/decomposition/NMF.ts:289 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/decomposition/NMF.ts:121 (opens in a new tab)
inverse_transform()
Transform data back to its original space.
Signature
inverse_transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.W? | ArrayLike | Transformed data matrix. |
Returns
Promise
<ArrayLike
>
Defined in: generated/decomposition/NMF.ts:322 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/decomposition/NMF.ts:357 (opens in a new tab)
transform()
Transform the data X according to the fitted NMF model.
Signature
transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training 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:390 (opens in a new tab)