Documentation
Classes
TruncatedSVD

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 (opens in a new tab)

Constructors

constructor()

Signature

new TruncatedSVD(opts?: object): TruncatedSVD;

Parameters

NameTypeDescription
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). Default Value 'randomized'
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. Default Value 2
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. Default Value 5
opts.n_oversamples?numberNumber of oversamples for randomized SVD solver. Not used by ARPACK. See randomized\_svd for a complete description. Default Value 10
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. Default Value 'auto'
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. Default Value 0

Returns

TruncatedSVD

Defined in: generated/decomposition/TruncatedSVD.ts:29 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/decomposition/TruncatedSVD.ts:27 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/decomposition/TruncatedSVD.ts:26 (opens in a new tab)

_py

PythonBridge

Defined in: generated/decomposition/TruncatedSVD.ts:25 (opens in a new tab)

id

string

Defined in: generated/decomposition/TruncatedSVD.ts:22 (opens in a new tab)

opts

any

Defined in: generated/decomposition/TruncatedSVD.ts:23 (opens in a new tab)

Accessors

components_

The right singular vectors of the input data.

Signature

components_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/TruncatedSVD.ts:378 (opens in a new tab)

explained_variance_

The variance of the training samples transformed by a projection to each component.

Signature

explained_variance_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/decomposition/TruncatedSVD.ts:403 (opens in a new tab)

explained_variance_ratio_

Percentage of variance explained by each of the selected components.

Signature

explained_variance_ratio_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/decomposition/TruncatedSVD.ts:428 (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/TruncatedSVD.ts:503 (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/TruncatedSVD.ts:478 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/decomposition/TruncatedSVD.ts:81 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/decomposition/TruncatedSVD.ts:85 (opens in a new tab)

singular_values_

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.

Signature

singular_values_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/decomposition/TruncatedSVD.ts:453 (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/TruncatedSVD.ts:142 (opens in a new tab)

fit()

Fit model on training data X.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:159 (opens in a new tab)

fit_transform()

Fit model to X and perform dimensionality reduction on X.

Signature

fit_transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
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:197 (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

NameTypeDescription
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:237 (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

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/decomposition/TruncatedSVD.ts:94 (opens in a new tab)

inverse_transform()

Transform X back to its original space.

Returns an array X_original whose transform would be X.

Signature

inverse_transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]New data.

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/TruncatedSVD.ts:275 (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

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/decomposition/TruncatedSVD.ts:312 (opens in a new tab)

transform()

Perform dimensionality reduction on X.

Signature

transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data.

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/TruncatedSVD.ts:345 (opens in a new tab)