Install & Compatibility
Where this runs
tested against v0.19.0 · 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
muslpy 3.10–3.910 runs
build_error
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 15.3s · import 4.759s · 361MB
371MB installed
● package 371MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
PCA
✓ from prince import PCA
MCA
✓ from prince import MCA
CA
✓ from prince import CA
MFA
✓ from prince import MFA
FAMD
✓ from prince import FAMD
This quickstart demonstrates how to use Prince's PCA implementation. It initializes a PCA model with 2 components, fits it to a sample Pandas DataFrame, and then transforms the data. Finally, it prints the transformed data and the explained inertia for each component.
import pandas as pd
from prince import PCA
# Sample data for PCA
X = pd.DataFrame({
'feature_a': [1, 2, 3, 4, 5],
'feature_b': [2, 3, 4, 5, 6],
'feature_c': [3, 4, 5, 6, 7]
})
# Initialize and fit PCA model
pca = PCA(n_components=2)
pca.fit(X)
# Transform the data
X_transformed = pca.transform(X)
print("Original data head:\n", X.head())
print("\nTransformed data head (2 components):\n", X_transformed.head())
print("\nExplained inertia per component:", pca.explained_inertia_)
Debug
Known issues
breakingThe attribute `explained_variance_ratio_` was renamed to `explained_inertia_` to better align with factor analysis terminology.fixReplace `model.explained_variance_ratio_` with `model.explained_inertia_`.
affects: 0.10.0 and later
breakingThe `weight_col` parameter in `CA`, `MCA`, and `MFA` models was removed.fixIf you need to apply observation weights, consider pre-processing your data or using a different library. The parameter is no longer supported in Prince.
affects: 0.14.0 and later
gotchaUnlike some other PCA implementations (e.g., `sklearn.decomposition.PCA`), `prince.PCA` only centers the data by default, but does not standardize (scale to unit variance).fixIf you require standardization, explicitly set `standardize=True` when initializing the PCA model, e.g., `PCA(n_components=2, standardize=True)`.
affects: All versions
Errors
Common errors & fixes
AttributeError: 'PCA' object has no attribute 'explained_variance_ratio_'
The attribute name for explained variance ratio changed from `explained_variance_ratio_` to `explained_inertia_` in version 0.10.0.
fixUpdate your code to use `pca.explained_inertia_` instead.
ValueError: Input data contains non-numeric values.
Methods like PCA, CA, and MFA expect purely numerical input data. You might be passing a DataFrame with categorical columns without prior encoding.
fixEnsure all input features are numerical. For categorical data, use one-hot encoding or label encoding, or consider using `prince.FAMD` which is designed for mixed data types.
TypeError: fit() missing 1 required positional argument: 'X'
You called the `fit()` method without providing the input data (feature matrix).
fixAlways pass your input data (e.g., a Pandas DataFrame or NumPy array) as the `X` argument: `model.fit(X)`.
Upgrade
Version history
0.19.0latest on PyPI · released May 5, 2026
Audit
Dependencies
pandasrequiredCommonly used for input data (DataFrames) and highly recommended for data preparation.
scikit-learnrequiredProvides a scikit-learn compatible API and some internal utilities.