InferComponents
#
- class robustica.InferComponents(max_variance_explained_ratio=0.8, n_components=None, copy=True, whiten=False, svd_solver='auto', tol=0.0, iterated_power='auto', random_state=None)#
Estimate the number of principal components needed to explain a certain amount of variance using sklearn.decomposition.PCA.
- Parameters
max_variance_explained_ratio (float, default=0.8) – Threshold of maximum variance explained by the desired number of components.
n_components (int, float or 'mle', default=None) –
Number of components to keep. if n_components is not set all components are kept:
n_components == min(n_samples, n_features)
If
n_components == 'mle'
andsvd_solver == 'full'
, Minka’s MLE is used to guess the dimension. Use ofn_components == 'mle'
will interpretsvd_solver == 'auto'
assvd_solver == 'full'
. If0 < n_components < 1
andsvd_solver == 'full'
, select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components. Ifsvd_solver == 'arpack'
, the number of components must be strictly less than the minimum of n_features and n_samples. Hence, the None case results in:n_components == min(n_samples, n_features) - 1
copy (bool, default=True) – If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.
whiten (bool, default=False) – When True (False by default) the components_ vectors are multiplied by the square root of n_samples and then divided by the singular values to ensure uncorrelated outputs with unit component-wise variances. Whitening will remove some information from the transformed signal (the relative variance scales of the components) but can sometime improve the predictive accuracy of the downstream estimators by making their data respect some hard-wired assumptions.
svd_solver ({'auto', 'full', 'arpack', 'randomized'}, default='auto') –
- If auto :
The solver is selected by a default policy based on X.shape and n_components: if the input data is larger than 500x500 and the number of components to extract is lower than 80% of the smallest dimension of the data, then the more efficient ‘randomized’ method is enabled. Otherwise the exact full SVD is computed and optionally truncated afterwards.
- If full :
run exact full SVD calling the standard LAPACK solver via scipy.linalg.svd and select the components by postprocessing
- If arpack :
run SVD truncated to n_components calling ARPACK solver via scipy.sparse.linalg.svds. It requires strictly 0 < n_components < min(X.shape)
- If randomized :
run randomized SVD by the method of Halko et al.
New in version 0.18.0.
tol (float, default=0.0) – Tolerance for singular values computed by svd_solver == ‘arpack’. Must be of range [0.0, infinity). .. versionadded:: 0.18.0
iterated_power (int or 'auto', default='auto') – Number of iterations for the power method computed by svd_solver == ‘randomized’. Must be of range [0, infinity). .. versionadded:: 0.18.0
random_state (int, RandomState instance or None, default=None) – Used when the ‘arpack’ or ‘randomized’ solvers are used. Pass an int for reproducible results across multiple function calls. See See Glossary. .. versionadded:: 0.18.0
- pca#
- Type
instance of sklearn.decomposition.PCA
- cumsum_#
Cumulative explained variance ratio.
- Type
np.array of length n_components
- inferred_components_#
Number of components required to explain max_variance_explained_ratio amount of variance.
- Type
int
Examples
from robustica.examples import make_sampledata from robustica import InferComponents X = make_sampledata(200, 50) ncomp = InferComponents().fit_predict(X) ncomp