Class: TruncatedSVD
Dimensionality reduction using truncated SVD (aka LSA).
This transformer performs linear dimensionality reduction by means of truncated singular value decomposition (SVD). Contrary to PCA, this estimator does not center the data before computing the singular value decomposition. This means it can work with sparse matrices efficiently.
In particular, truncated SVD works on term count/tf-idf matrices as returned by the vectorizers in sklearn.feature_extraction.text
. In that context, it is known as latent semantic analysis (LSA).
This estimator supports two algorithms: a fast randomized SVD solver, and a “naive” algorithm that uses ARPACK as an eigensolver on X \* X.T
or X.T \* X
, whichever is more efficient.
Read more in the User Guide.
Constructors
new TruncatedSVD()
new TruncatedSVD(
opts
?):TruncatedSVD
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.algorithm ? | "randomized" | "arpack" | SVD solver to use. Either “arpack” for the ARPACK wrapper in SciPy (scipy.sparse.linalg.svds), or “randomized” for the randomized algorithm due to Halko (2009). |
opts.n_components ? | number | Desired dimensionality of output data. If algorithm=’arpack’, must be strictly less than the number of features. If algorithm=’randomized’, must be less than or equal to the number of features. The default value is useful for visualisation. For LSA, a value of 100 is recommended. |
opts.n_iter ? | number | Number of iterations for randomized SVD solver. Not used by ARPACK. The default is larger than the default in randomized_svd to handle sparse matrices that may have large slowly decaying spectrum. |
opts.n_oversamples ? | number | Number of oversamples for randomized SVD solver. Not used by ARPACK. See randomized_svd for a complete description. |
opts.power_iteration_normalizer ? | "auto" | "QR" | "LU" | "none" | Power iteration normalizer for randomized SVD solver. Not used by ARPACK. See randomized_svd for more details. |
opts.random_state ? | number | Used during randomized svd. Pass an int for reproducible results across multiple function calls. See Glossary. |
opts.tol ? | number | Tolerance for ARPACK. 0 means machine precision. Ignored by randomized SVD solver. |
Returns TruncatedSVD
Defined in generated/decomposition/TruncatedSVD.ts:29
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/decomposition/TruncatedSVD.ts:27 |
_isInitialized | boolean | false | generated/decomposition/TruncatedSVD.ts:26 |
_py | PythonBridge | undefined | generated/decomposition/TruncatedSVD.ts:25 |
id | string | undefined | generated/decomposition/TruncatedSVD.ts:22 |
opts | any | undefined | generated/decomposition/TruncatedSVD.ts:23 |
Accessors
components_
Get Signature
get components_():
Promise
<ArrayLike
[]>
The right singular vectors of the input data.
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/TruncatedSVD.ts:398
explained_variance_
Get Signature
get explained_variance_():
Promise
<ArrayLike
>
The variance of the training samples transformed by a projection to each component.
Returns Promise
<ArrayLike
>
Defined in generated/decomposition/TruncatedSVD.ts:423
explained_variance_ratio_
Get Signature
get explained_variance_ratio_():
Promise
<ArrayLike
>
Percentage of variance explained by each of the selected components.
Returns Promise
<ArrayLike
>
Defined in generated/decomposition/TruncatedSVD.ts:448
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/TruncatedSVD.ts:523
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/decomposition/TruncatedSVD.ts:498
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/decomposition/TruncatedSVD.ts:81
singular_values_
Get Signature
get singular_values_():
Promise
<ArrayLike
>
The singular values corresponding to each of the selected components. The singular values are equal to the 2-norms of the n_components
variables in the lower-dimensional space.
Returns Promise
<ArrayLike
>
Defined in generated/decomposition/TruncatedSVD.ts:473
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/TruncatedSVD.ts:133
fit()
fit(
opts
):Promise
<any
>
Fit model on training data X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Training data. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/decomposition/TruncatedSVD.ts:150
fit_transform()
fit_transform(
opts
):Promise
<ArrayLike
[]>
Fit model to X and perform dimensionality reduction on X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Training data. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/TruncatedSVD.ts:187
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
Parameter | 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/TruncatedSVD.ts:226
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/decomposition/TruncatedSVD.ts:262
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/decomposition/TruncatedSVD.ts:94
inverse_transform()
inverse_transform(
opts
):Promise
<ArrayLike
[]>
Transform X back to its original space.
Returns an array X_original whose transform would be X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | New data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/TruncatedSVD.ts:298
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/decomposition/TruncatedSVD.ts:334
transform()
transform(
opts
):Promise
<ArrayLike
[]>
Perform dimensionality reduction on X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | New data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/TruncatedSVD.ts:366