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.

Python Reference

Constructors

new TruncatedSVD()

new TruncatedSVD(opts?): TruncatedSVD

Parameters

ParameterTypeDescription
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?numberDesired 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?numberNumber 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?numberNumber 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?numberUsed during randomized svd. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.tol?numberTolerance for ARPACK. 0 means machine precision. Ignored by randomized SVD solver.

Returns TruncatedSVD

Defined in generated/decomposition/TruncatedSVD.ts:29

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/decomposition/TruncatedSVD.ts:27
_isInitializedbooleanfalsegenerated/decomposition/TruncatedSVD.ts:26
_pyPythonBridgeundefinedgenerated/decomposition/TruncatedSVD.ts:25
idstringundefinedgenerated/decomposition/TruncatedSVD.ts:22
optsanyundefinedgenerated/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

ParameterType
pythonBridgePythonBridge

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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining data.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining data.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly 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

ParameterTypeDescription
optsobject-
opts.routing?anyA 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

ParameterType
pyPythonBridge

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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeNew data.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/TruncatedSVD.ts:366