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.
eps : float, default=0.1
Parameter to control the quality of the embedding according to
the Johnson-Lindenstrauss lemma when n_components is set to
‘auto’. The value should be strictly positive.
Smaller values lead to better embedding and higher number of
dimensions (n_components) in the target projection space.
compute_inverse_components : bool, default=False
Learn the inverse transform by computing the pseudo-inverse of the
components during fit. Note that computing the pseudo-inverse does not
scale well to large matrices.
random_state : int, RandomState instance or None, default=None
Controls 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.
Attributes:
n_components_ : int
Concrete number of components computed when n_components=”auto”.
components_ : ndarray of shape (n_components, n_features)
Random matrix used for the projection.
inverse_components_ : ndarray of shape (n_features, n_components)
Pseudo-inverse of the components, only computed if
compute_inverse_components is True.
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
Training set: only the shape is used to find optimal random
matrix dimensions based on the theory referenced in the
afore mentioned papers.
y : Ignored
Not used, present here for API consistency by convention.
Returns:
self : object
BaseRandomProjection class instance.
fit_transform(X, y=None, **fit_params)
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:
X : array-like of shape (n_samples, n_features)
Input samples.
y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
**fit_params : dict
Additional fit parameters.
Pass only if the estimator accepts additional params in its fit method.
Returns:
X_new : ndarray array of shape (n_samples, n_features_new)
Transformed array.
get_feature_names_out(input_features=None)
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:
input_features : array-like of str or None, default=None
Only used to validate feature names with the names seen in fit.
Returns:
feature_names_out : ndarray of str objects
Transformed feature names.
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing
mechanism works.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Parameters:
**params : dict
Estimator parameters.
Returns:
self : estimator instance
Estimator instance.
transform(X)
Project the data by using matrix product with the random matrix.
Parameters:
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
The input data to project into a smaller dimensional space.
Returns:
X_new : ndarray of shape (n_samples, n_components)
Projected array.
New
Added in version 0.24.
feature_names_in_ : ndarray of shape (n_features_in_,)
Names of features seen during fit. Defined only when X
has feature names that are all strings.