Documentation
Classes
SparseRandomProjection

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

Constructors

constructor()

Signature

new SparseRandomProjection(opts?: object): SparseRandomProjection;

Parameters

NameTypeDescription
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. Default Value false
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. Default Value false
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. Default Value 'auto'
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. Default Value 0.1
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. Default Value 'auto'
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 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/random_projection/SparseRandomProjection.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/random_projection/SparseRandomProjection.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/random_projection/SparseRandomProjection.ts:21 (opens in a new tab)

id

string

Defined in: generated/random_projection/SparseRandomProjection.ts:18 (opens in a new tab)

opts

any

Defined in: generated/random_projection/SparseRandomProjection.ts:19 (opens in a new tab)

Accessors

components_

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

Signature

components_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/random_projection/SparseRandomProjection.ts:441 (opens in a new tab)

density_

Concrete density computed from when density = “auto”.

Signature

density_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/random_projection/SparseRandomProjection.ts:495 (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/random_projection/SparseRandomProjection.ts:549 (opens in a new tab)

inverse_components_

Pseudo-inverse of the components, only computed if compute\_inverse\_components is true.

Signature

inverse_components_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/random_projection/SparseRandomProjection.ts:468 (opens in a new tab)

n_components_

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

Signature

n_components_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/random_projection/SparseRandomProjection.ts:414 (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/random_projection/SparseRandomProjection.ts:522 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/random_projection/SparseRandomProjection.ts:82 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/random_projection/SparseRandomProjection.ts:86 (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/random_projection/SparseRandomProjection.ts:145 (opens in a new tab)

fit()

Generate a sparse random projection matrix.

Signature

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

Parameters

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

fit_transform()

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit\_params and returns a transformed version of X.

Signature

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

Parameters

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

Returns

Promise<any[]>

Defined in: generated/random_projection/SparseRandomProjection.ts:204 (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/random_projection/SparseRandomProjection.ts:258 (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/random_projection/SparseRandomProjection.ts:95 (opens in a new tab)

inverse_transform()

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.

Signature

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

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/random_projection/SparseRandomProjection.ts:300 (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/random_projection/SparseRandomProjection.ts:340 (opens in a new tab)

transform()

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

Signature

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

Parameters

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

Returns

Promise<ArrayLike>

Defined in: generated/random_projection/SparseRandomProjection.ts:377 (opens in a new tab)