Registry / ai-ml / pca
library2.10.2pypypi✓ verified 84d ago

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 pca
INSTALL
IMPORT
SIG · PCA
P
pca
ai-mlpythonv2.10.2
Install
21.1s avg
Import
6595ms
Disk
503MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.10.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 21.1s · import 6.595s · 482MB
503MB installed
● package 503MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pca
from pca import pca
PCA
from sklearn.decomposition import PCA
from pca import PCA
The `pca` library provides its own `pca` class (lowercase 'p'). The uppercase 'PCA' is typically imported from scikit-learn's `sklearn.decomposition` module. Confusing these can lead to missing methods.

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.

import numpy as np from pca import pca import pandas as pd # Sample data X = pd.DataFrame(np.random.rand(100, 10), columns=[f'feature_{i}' for i in range(10)]) # Initialize PCA model with 3 components model = pca(n_components=3) # Fit and transform the data out = model.fit_transform(X) print("Explained variance ratio:", model.results['explained_var']) print("Principal Components (transformed data shape):", out['PC'].shape) # To display the biplot (requires matplotlib to be installed) # import matplotlib.pyplot as plt # model.plot() # plt.show()
Debug
Known issues
gotchaPCA is highly sensitive to the scale of input data. Features with larger value ranges or variances can disproportionately influence the principal components if data is not scaled (e.g., using `sklearn.preprocessing.StandardScaler`) prior to PCA.
fix
Always preprocess your data using a scaling method like `StandardScaler` from scikit-learn before applying PCA, especially if features have different units or ranges.
affects: All versions
gotchaWhen using the plotting features of `pca`, specifically with `matplotlib` versions 3.10 and above, you might encounter warnings related to `get_cmap`.
fix
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.
affects: >=2.10.0 (with matplotlib >= 3.10)
gotchaThere's a separate `PCA` class within scikit-learn (`sklearn.decomposition.PCA`). Attempting to use methods unique to the `erdogant/pca` package (like `.plot()` or `.biplot()`) on a `sklearn.decomposition.PCA` object will result in an `AttributeError`.
fix
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.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name 'pca' from 'pca'
You are trying to import 'pca' (lowercase) as a class directly from the package, but Python's import system might resolve 'pca' as the package itself rather than its main class/function if not structured carefully, or you might be trying to import 'PCA' (uppercase) which is not the main class of this library.
fix
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'.
AttributeError: 'PCA' object has no attribute 'biplot'
You are likely using scikit-learn's `sklearn.decomposition.PCA` class, which does not have a `biplot` method. The `biplot` method is a feature provided by the `erdogant/pca` library.
fix
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`.
ValueError: not enough features to compute (n_components) components
This error occurs when the `n_components` parameter specified for PCA is greater than or equal to the number of features (columns) in your input data. PCA cannot create more components than existing features.
fix
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'.
Upgrade
Version history
2.10.2latest on PyPI · released Feb 21, 2026
Audit
Dependencies
scikit-learnrequiredCore functionality is built on sklearn for PCA algorithms.
numpyrequiredFundamental library for numerical operations and data handling.
matplotlibrequiredRequired for plotting functions like biplots and explained variance.
Agent activity
4 hits · last 30 days
node
4
Resources
pca — pip install pca · libregistry