MCPcopy Create free account
hub / github.com/MaxHalford/prince

github.com/MaxHalford/prince @v0.20.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.20.1 ↗ · + Follow
323 symbols 886 edges 22 files 117 documented · 36% updated 7d ago★ 1,4735 open issues

Browse by type

Functions 259 Types & classes 30 Endpoints 34
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

prince_logo

documentation

pypi

pepy

pepy_month

CI

license

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

>>> chart = pca.plot(dataset)

<i>This chart is interactive, which doesn't show on GitHub. The green points are the column loadings.</i>
>>> chart = pca.plot(
...     dataset,
...     show_row_labels=True,
...     show_row_markers=False,
...     row_labels_column='athlete',
...     color_rows_by='competition'
... )

Installation

pip install prince

🎨 Prince uses Altair for making charts.

Methods

flowchart TD
    groups?(Groups of columns?) --> |"✅"| MFA
    groups? --> |"❌"| cat?(Categorical data?)
    cat? --> |"✅"| num_too?(Numerical data too?)
    num_too? --> |"✅"| FAMD
    num_too? --> |"❌"| multiple_cat?(More than two columns?)
    multiple_cat? --> |"✅"| MCA
    multiple_cat? --> |"❌"| CA
    cat? --> |"❌"| shapes?(Analysing shapes?)
    shapes? --> |"✅"| GPA
    shapes? --> |"❌"| manifold?(Data on a manifold?)
    manifold? --> |"✅"| PGA
    manifold? --> |"❌"| PCA

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)

Principal geodesic analysis (PGA)

Correctness

Prince is tested against scikit-learn and FactoMineR. For the latter, rpy2 is used to run code in R, and convert the results to Python, which allows running automated tests. PGA is tested against geomstats. See more in the tests directory.

Citation

Please use this citation if you use this software as part of a scientific publication.

@software{Halford_Prince,
    author = {Halford, Max},
    license = {MIT},
    title = {{Prince}},
    url = {https://github.com/MaxHalford/prince}
}

License

The MIT License (MIT). Please see the license file for more information.

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 220
Function 39
Route 34
Class 30

Languages

Python100%

Modules by API surface

tests/test_mfa.py36 symbols
prince/mfa.py33 symbols
tests/test_pga.py27 symbols
prince/pca.py27 symbols
tests/test_famd.py22 symbols
prince/mca.py20 symbols
prince/ca.py20 symbols
prince/famd.py17 symbols
tests/test_pca.py13 symbols
tests/test_mca.py13 symbols
tests/test_ca.py13 symbols
prince/pga.py13 symbols

For agents

$ claude mcp add prince \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page