watex.analysis.nPCA#
- watex.analysis.nPCA(X, n_components=None, *, view=False, return_X=True, plot_kws=None, n_axes=None, **pca_kws)[source]#
Normal Principal Components analysis (PCA)
PCA is by far the most popular dimensional reduction algorithm. First it identifies the hyperplane that lies closest to the data and project it to the data onto it.
- Parameters:
X (Ndarray ( M x N matrix where
M=m-samples, &N=n-features)) – Training set; Denotes data that is observed at training and prediction time, used as independent variables in learning. When a matrix, each sample may be represented by a feature vector, or a vector of precomputed (dis)similarity with each training sample.Xmay also not be a matrix, and may require a feature extractor or a pairwise metric to turn it into one before learning a model.n_components (int, optional) – Number of dimension to preserve. If`n_components` is ranged between float 0. to 1., it indicated the number of variance ratio to preserve. If
Noneas default value the number of variance to preserve is95%.return_X (bool, default =True ,) – return the train set transformed with most representative varaince ratio.
view (bool,default=False,) – Plot the explained varaince as a function of number of dimension.
n_axes (int, optional,) – Number of importance components to retrieve the variance ratio. If
Nonethe features importance is computed using the cumulative variance representative of 95% .pca_kws (dict,) – Additional matplotlib.pyplot keywords arguments passed to
sklearn.decomposition.PCA
- Returns:
The transformed training set or the PCA container attributes for plotting purpose.
- Return type:
X or nPCA object,
Examples
>>> from watex.analysis.dimensionality import nPCA >>> from watex.datasets import fetch_data >>> X, _= fetch_data('Bagoue analysed dataset') >>> pca = nPCA(X, 0.95, n_axes =3, return_X=False) >>> pca.components_ >>> pca.feature_importances_