Factor analysis in Python: PCA, CA, MCA, MFA, FAMD, GPA, PGA
Actively maintained. Last release 5 weeks ago. A safe choice.
pip install prince
Prince is a Python library for multivariate exploratory data analysis in Python. It includes a variety of methods for summarizing tabular data, including principal component analysis (PCA) and correspondence analysis (CA). Prince provides efficient implementations, using a scikit-learn API.
I made Prince when I was at university, back in 2016. I spent a significant amount of time in 2022 to revamp the entire package. It is thoroughly tested and supports many features, such as supplementary row/columns, as well as row/column weights.
Example usage
>>> import prince
>>> dataset = prince.datasets.load_decathlon()
>>> decastar = dataset.query('competition == "Decastar"')
>>> pca = prince.PCA(n_components=5)
>>> pca = pca.fit(decastar, supplementary_columns=['rank', 'points'])
>>> pca.eigenvalues_summary
eigenvalue % of variance % of variance (cumulative)
component
0 3.114 31.14% 31.14%
1 2.027 20.27% 51.41%
2 1.390 13.90% 65.31%
3 1.321 13.21% 78.52%
4 0.861 8.61% 87.13%
>>> pca.transform(dataset).tail()
component 0 1 2 3 4
competition athlete
OlympicG Lorenzo 2.070933 1.545461 -1.272104 -0.215067 -0.515746
Karlivans 1.321239 1.318348 0.138303 -0.175566 -1.484658
Korkizoglou -0.756226 -1.975769 0.701975 -0.642077 -2.621566
Uldal 1.905276 -0.062984 -0.370408 -0.007944 -2.040579
Casarsa 2.282575 -2.150282 2.601953 1.196523 -3.571794