erdogant/pca

pca: A Python Package for Principal Component Analysis.

📦 pca – A lightweight Python wrapper for Principal Component Analysis

What it ispca is a small, pure‑Python package that makes it easy to run Principal Component Analysis (PCA) and related linear‑dimensionality‑reduction methods (SparsePCA, TruncatedSVD) while providing a richer set of visualisations and utilities than the raw scikit‑learn API.

Why you might care – If you already use sklearn.decomposition.PCA but want:

  • ready‑made biplots, loading vectors and 3‑D visualisations,
  • automatic out‑lier detection (Hotelling T², SPE/D‑ModX),
  • simple extraction of the most important original features,
  • utilities to normalise/remove variance bias, save/load fitted models, and map new data into an existing PCA space – all with a single pca object – this library saves you a lot of boiler‑plate code.

🎯 Core capabilities (as listed in the README)

Feature What it does
Fit & Transform Wraps scikit‑learn’s PCA/SparsePCA/TruncatedSVD, exposing a single fit_transform method that returns the reduced coordinates.
Biplot & Loadings Plots samples in the PC space together with arrows that represent each original variable’s contribution (loadings).
Explained‑variance plot Visualises how much variance each component captures, helping you pick the right number of PCs.
Best‑performing features Returns a ranked list of original variables that contribute most to the selected components.
Scatterplot Simple 2‑D scatter of the chosen PCs, with optional colour/size encoding.
Outlier detection Implements Hotelling’s T² and SPE/D‑ModX statistics to flag observations that lie far from the model centre.
Normalize out variance Removes systematic bias from the data before PCA (e.g., scaling each PC to unit variance).
Save & load Serialises a fitted pca object to disk and reloads it later, preserving the transformation matrix.
Discrete‑data support Works with categorical/discrete datasets after appropriate encoding (the README mentions examples).

🚀 Getting started

# install from PyPI
pip install pca
from pca import pca

# Example – classic Iris dataset
model = pca(n_components=2)          # choose number of PCs
X_red = model.fit_transform(X)      # X is a NumPy / pandas matrix
model.biplot()                      # quick visualisation

The documentation (linked from the badge bar) contains a full Quick‑Start notebook, Colab links, and a gallery of plots.


📚 Documentation & learning resources

  • API referencehttps://erdogant.github.io/pca/
  • Tutorial notebooks – Colab notebook badge in the README; see the Examples page for step‑by‑step use cases.
  • Medium articles – Short guides on PCA basics, outlier detection, and feature importance (links provided in the table).
  • Gumroad – Paid/extended write‑ups and podcast episodes for deeper dives (optional).

👥 Community & maintenance

  • Maintainer – Erdogan Taskesen (GitHub erdogant).
  • License – MIT (permissive, commercial‑friendly).
  • Activity – Badges show active status, recent releases, and a steady download count (tens of thousands/month).
  • Contributions – Open to pull requests; contributors are displayed via contrib.rocks.
  • Support – Donation button (Buy‑me‑a‑coffee) for the maintainer.

TL;DR

pca is a thin wrapper around scikit‑learn’s linear‑decomposition tools that adds ready‑made visualisations, outlier detection, and convenience functions for feature importance and model persistence. It’s useful for data‑science practitioners who need quick, publication‑ready PCA plots without writing custom matplotlib code.

Related

  • Project
  • Project
  • Project
  • Project
  • Project