ClusterLOCO
Cluster LOCO: Feature Importance for Interpreting Clusters
clusterloco is a Python package for Cluster LOCO feature importance methods for clustering interpretability.
Cluster LOCO is a model-agnostic framework for quantifying feature importance in clustering. The package provides methods that evaluate how much removing a feature affects the generalizability and stability of a clustering solution, enabling feature-level interpretation for unsupervised learning workflows.
Installation
Package
Our package can be installed directly from PyPI:
pip install clusterloco
or for additional experiment dependencies, use
pip install "clusterloco[experiments]"
Development installation
Clone the repository and install the package in editable mode:
git clone https://github.com/DataSlingers/ClusterLOCO.git
cd ClusterLOCO
pip install -e .
To check that the package is correctly installed:
python -c "import clim; print(clim.__file__)"
python -c "from clim import ClusterLOCOMP; print('import ok')"
To build the package:
python -m pip install build
python -m build
This should create a source distribution and wheel in the dist/directory.
For experiment dependencies, such as anndata and scanpy, install:
pip install -e ".[experiments]"
Requirements
The core package requires Python 3.10 or higher. Core dependencies include:
numpy
scipy
pandas
scikit-learn
joblib
tqdm
matplotlib
seaborn
leidenalg
igraph
Optional experiment dependencies include:
anndata
scanpy
Get started
The package offers Cluster LOCO via data splitting, via minipatches and with adaptive recursive trimming. Two example notebooks for running our models are available under the example folder with simulated data and a real application to PBMC 68k data. For the latter you will need to install anndata and scanpy.
Cluster LOCO Split
Cluster LOCO Split is recommended for data with few features (less than 10 features).
from clim.data_splitting import Cluster_LOCO_Split
from clim.utils import hinge_error
Basic usage: for any sklearn clustering algorithm, default transfer classifier is RandomForestClassifier.
from sklearn.cluster import SpectralClustering
model = SpectralClustering(n_clusters=K)
feature_importance, feature_importance_se = Cluster_LOCO_Split(X_train, X_test, model=model, error_metric=hinge_error, use_proba=True, seed=42)
Cluster LOCO-MP
Cluster LOCO-MP implements a minipatch ensemble version of Cluster LOCO. This approach is suited for large data.
from clim import ClusterLOCOMP
Basic usage: for any sklearn clustering algorithm, first fit() the minipatch model, then compute the feature importance via score(). We recommend to use parallelization during model fitting but not during computing scores where the overhead can be consequential.
g = ClusterLOCOMP(base_clusterer = model, base_classifier = RandomForestClassifier(), K=3, B=500)
g.fit(X, standardize=False, alpha_N = 0.2, alpha_M = 0.2, parallel=par)
out = g.score(error_metric=hinge_error, agg='mean', proba_error=True, parallel_features=False)
Cluster LOCO-RAMPART
Cluster LOCO-RAMPART is a sped-up version of Cluster LOCO-MP based on adaptive recursive trimming of active feature set. We recommend using this with high-dimensional data.
Basic usage:
from clim import ClusterLOCO_RAMPART, RAMPART
from clim.utils import transform_scores_to_ranking
RAMPART directly fits the model and computes the scores.
gen_fn = ClusterLOCO_RAMPART(base_clusterer=model, K=3, error_metric=hinge_error, parallel_MP=True,
parallel={"n_jobs_features": 3, "backend": "loky", "prefer": "processes", "verbose": 0},
standardize=False, alpha_N = 0.2, alpha_M = 0.2)
out = RAMPART(X, generalizability_fn=gen_fn, B=1000, ranking_fn=transform_scores_to_ranking, top_k=50)
Package structure
ClusterLOCO/
├── pyproject.toml
├── README.md
└── clim/
├── __init__.py
├── minipatches/
├── data_splitting/
├── models/
└── utils/
└── benchmarking/
└── simulations/
└── example/
└── paper_figures/
This repository additionally contains code to reproduce the results from our paper: the folder paper_figures contains the notebook to make the main figures from our paper.
Citation
If you use this package, please cite the corresponding Cluster LOCO paper.
@preprint{he2026clusterloco,
title={Cluster LOCO: Feature Importance for Interpreting Clusters},
author={He, Claire and Allen, Genevera},
url={https://arxiv.org/pdf/2606.14592},
year={2026}
}
Release files for clusterloco 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| clusterloco-0.1.0.tar.gz | 39.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clusterloco-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 81.6 kB
Release files / clusterloco-0.1.0.tar.gz
| Download URL | clusterloco-0.1.0.tar.gz |
|---|---|
| Size | 39.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0230e1a400eaee8e783c69d79a45caf52ce13ccde445d7eae5a2d30c02212912
|
|
BLAKE2b-256 checksum How to use checksums |
585cd373dd6a939cb6279176aa0f84f5ce4ab7fad9180432d5d51eb37e5105c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.
Transparency logRelease files / clusterloco-0.1.0-py3-none-any.whl
| Download URL | clusterloco-0.1.0-py3-none-any.whl |
|---|---|
| Size | 42.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2f86bc0c39f704a8659e5cb0e39ad3b545f8e315521438ea1fb4c98122739ab
|
|
BLAKE2b-256 checksum How to use checksums |
9547a328af3cd66d9d40035dcddb02a6657f32dcc20b4b25e4bc7400951e6f36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.
Transparency log