mojolearn.GaussianRandomProjection#
- class mojolearn.GaussianRandomProjection(n_components='auto', *, eps=0.1, compute_inverse_components=False, random_state=None, numeric_mode=None)[source]#
Bases:
_RandomProjectionReduce dimension with a Gaussian random matrix.
Follows scikit-learn’s
GaussianRandomProjection: each component entry is drawn from N(0, 1 / n_components).- Parameters:
n_components (int or “auto”, default “auto”) – Target dimension.
"auto"usesjohnson_lindenstrauss_min_dim(n_samples, eps=eps).eps (float, default 0.1) – Distortion bound used by
n_components="auto"through johnson_lindenstrauss_min_dim().compute_inverse_components (bool, default False) – Compute
inverse_components_(the pseudo-inverse of the components) infit, needed byinverse_transform. Raises ValueError if the components are rank deficient.random_state (int or None, default None) – Seed of mojolearn’s counter-based random generator; None means 0. The same seed gives the same matrix on every device, but not the matrix scikit-learn draws for that seed.
numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Variables:
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 64), dtype=np.float32) >>> model = mojolearn.GaussianRandomProjection(n_components=8, random_state=0).fit(X) >>> model.transform(X).shape (1000, 8)
- __init__(n_components='auto', *, eps=0.1, compute_inverse_components=False, random_state=None, numeric_mode=None)[source]#
Methods
fit(X[, y])Draw the projection matrix for X's shape.
fit_transform(X[, y])Fit to X, then return
transform(X).get_params([deep])Return this estimator's constructor parameters.
inverse_transform(X)Map projected data back with the pseudo-inverse of the components.
set_params(**params)Set constructor parameters by keyword.
transform(X)Project X:
X @ components_.T.Attributes
components_The random projection matrix, shape (n_components, n_features).