pca is a Python package for Principal Component Analysis (PCA), providing extended functionality beyond basic scikit-learn implementations. It leverages sklearn's core for compatibility while offering features like SparsePCA and TruncatedSVD, comprehensive analysis, and advanced plotting capabilities such as biplots, explained variance plots, outlier detection, and feature importance extraction. The current version is 2.10.2, and it is actively maintained.
pip install pcaVerified import paths — ran on the pinned version, not inferred.
Initializes the `pca` model, fits it to sample data, and transforms the data into principal components. It also shows how to access the explained variance and the transformed data. Plotting functionality is also available.
Always preprocess your data using a scaling method like `StandardScaler` from scikit-learn before applying PCA, especially if features have different units or ranges.
Ensure you are using the latest `pca` library version which often includes fixes for newer dependency versions. If warnings persist, refer to the library's GitHub issues for potential workarounds or updates, or consider temporarily downgrading `matplotlib` if critical for production.
Ensure you are importing and instantiating the correct PCA object: `from pca import pca` for this package, or `from sklearn.decomposition import PCA` for scikit-learn's native implementation.
The correct import for the main PCA class in this library is `from pca import pca` (lowercase `pca` for the class name) or ensure your environment doesn't have conflicting modules named 'pca'.
Ensure you are importing the `pca` class from the `pca` library: `from pca import pca`. Then, create an instance of this class to access its extended methods like `biplot`.
Reduce the value of `n_components` to be less than the number of features in your dataset. For `sklearn.decomposition.PCA` specifically, it must be strictly less than `min(n_samples, n_features)` when using solvers like 'arpack'.