Find a ‘safe’ number of components to randomly project to.
The distortion introduced by a random projection p only changes the
distance between two points by a factor (1 +- eps) in a euclidean space
with good probability. The projection p is an eps-embedding as defined
by:
Where u and v are any rows taken from a dataset of shape (n_samples,
n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian
N(0, 1) matrix of shape (n_components, n_features) (or a sparse
Achlioptas matrix).
The minimum number of components to guarantee the eps-embedding is
given by:
Note that the number of dimensions is independent of the original
number of features but instead depends on the size of the dataset:
the larger the dataset, the higher is the minimal dimensionality of
an eps-embedding.
Number of samples that should be an integer greater than 0. If an array
is given, it will compute a safe number of components array-wise.
eps : float or array-like of shape (n_components,), dtype=float, default=0.1
Maximum distortion rate in the range (0, 1) as defined by the
Johnson-Lindenstrauss lemma. If an array is given, it will compute a
safe number of components array-wise.
Returns:
n_components : int or ndarray of int
The minimal number of components to guarantee with good probability
an eps-embedding with n_samples.