Prince - Factor Analysis in Python

0.17.0 · active · verified Fri Apr 17

Prince is a Python library for various factor analysis methods, including Principal Component Analysis (PCA), Correspondence Analysis (CA), Multiple Correspondence Analysis (MCA), Multiple Factor Analysis (MFA), Factor Analysis of Mixed Data (FAMD), Generalized Procrustes Analysis (GPA), and Procrustes Global Analysis (PGA). As of version 0.17.0, it offers a scikit-learn compatible API, making it easy to integrate into existing data science workflows. The project is actively maintained with a relatively steady release cadence, incorporating new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

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_)

view raw JSON →