DocumentationClassesSparseRandomProjection

Class: SparseRandomProjection

Reduce dimensionality through sparse random projection.

Sparse random matrix is an alternative to dense random projection matrix that guarantees similar embedding quality while being much more memory efficient and allowing faster computation of the projected data.

If we note s \= 1 / density the components of the random matrix are drawn from:

Python Reference

Constructors

new SparseRandomProjection()

new SparseRandomProjection(opts?): SparseRandomProjection

Parameters

ParameterTypeDescription
opts?object-
opts.compute_inverse_components?booleanLearn the inverse transform by computing the pseudo-inverse of the components during fit. Note that the pseudo-inverse is always a dense array, even if the training data was sparse. This means that it might be necessary to call inverse_transform on a small batch of samples at a time to avoid exhausting the available memory on the host. Moreover, computing the pseudo-inverse does not scale well to large matrices.
opts.dense_output?booleanIf true, ensure that the output of the random projection is a dense numpy array even if the input and random projection matrix are both sparse. In practice, if the number of components is small the number of zero components in the projected data will be very small and it will be more CPU and memory efficient to use a dense representation. If false, the projected data uses a sparse representation if the input is sparse.
opts.density?number | "auto"Ratio in the range (0, 1] of non-zero component in the random projection matrix. If density = ‘auto’, the value is set to the minimum density as recommended by Ping Li et al.: 1 / sqrt(n_features). Use density = 1 / 3.0 if you want to reproduce the results from Achlioptas, 2001.
opts.eps?numberParameter to control the quality of the embedding according to the Johnson-Lindenstrauss lemma when n_components is set to ‘auto’. This value should be strictly positive. Smaller values lead to better embedding and higher number of dimensions (n_components) in the target projection space.
opts.n_components?number | "auto"Dimensionality of the target projection space. n_components can be automatically adjusted according to the number of samples in the dataset and the bound given by the Johnson-Lindenstrauss lemma. In that case the quality of the embedding is controlled by the eps parameter. It should be noted that Johnson-Lindenstrauss lemma can yield very conservative estimated of the required number of components as it makes no assumption on the structure of the dataset.
opts.random_state?numberControls the pseudo random number generator used to generate the projection matrix at fit time. Pass an int for reproducible output across multiple function calls. See Glossary.

Returns SparseRandomProjection

Defined in generated/random_projection/SparseRandomProjection.ts:25

Properties

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

Accessors

components_

Get Signature

get components_(): Promise<any[]>

Random matrix used for the projection. Sparse matrix will be of CSR format.

Returns Promise<any[]>

Defined in generated/random_projection/SparseRandomProjection.ts:459


density_

Get Signature

get density_(): Promise<any>

Concrete density computed from when density = “auto”.

Returns Promise<any>

Defined in generated/random_projection/SparseRandomProjection.ts:513


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/random_projection/SparseRandomProjection.ts:567


inverse_components_

Get Signature

get inverse_components_(): Promise<ArrayLike[]>

Pseudo-inverse of the components, only computed if compute_inverse_components is true.

Returns Promise<ArrayLike[]>

Defined in generated/random_projection/SparseRandomProjection.ts:486


n_components_

Get Signature

get n_components_(): Promise<number>

Concrete number of components computed when n_components=”auto”.

Returns Promise<number>

Defined in generated/random_projection/SparseRandomProjection.ts:432


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/random_projection/SparseRandomProjection.ts:540


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/random_projection/SparseRandomProjection.ts:82

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/random_projection/SparseRandomProjection.ts:138


fit()

fit(opts): Promise<any>

Generate a sparse random projection matrix.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining set: only the shape is used to find optimal random matrix dimensions based on the theory referenced in the afore mentioned papers.
opts.y?anyNot used, present here for API consistency by convention.

Returns Promise<any>

Defined in generated/random_projection/SparseRandomProjection.ts:155


fit_transform()

fit_transform(opts): Promise<any[]>

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/random_projection/SparseRandomProjection.ts:196


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/random_projection/SparseRandomProjection.ts:244


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/random_projection/SparseRandomProjection.ts:282


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/random_projection/SparseRandomProjection.ts:95


inverse_transform()

inverse_transform(opts): Promise<ArrayLike[]>

Project data back to its original space.

Returns an array X_original whose transform would be X. Note that even if X is sparse, X_original is dense: this may use a lot of RAM.

If compute_inverse_components is false, the inverse of the components is computed during each call to inverse_transform which can be costly.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeData to be transformed back.

Returns Promise<ArrayLike[]>

Defined in generated/random_projection/SparseRandomProjection.ts:322


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/random_projection/SparseRandomProjection.ts:360


transform()

transform(opts): Promise<ArrayLike>

Project the data by using matrix product with the random matrix.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe input data to project into a smaller dimensional space.

Returns Promise<ArrayLike>

Defined in generated/random_projection/SparseRandomProjection.ts:396