CARVE
Cluster Analysis with Resampling for Validation and Exploration
Choosing the number of clusters is hard, especially for high-dimensional biological data where standard internal clustering validation indices (CVIs) are often unreliable. CARVE measures clustering robustness through two resampling-based concepts: stability (reproducibility of cluster assignments under data subsampling) and generalizability (agreement between held-out cluster labels and predictions from a classifier trained on a subsample of the data). CARVE reports global, cluster-level, and sample-level diagnostics with visualizations, all through a scikit-learn-compatible API.
Features
- Scikit-learn-compatible API:
CARVEextendsBaseEstimatorwith afit/get_labels/get_kworkflow - Stability (ARI on subsample overlap) and generalizability (ARI on held-out predictions) metrics
- Diagnostics at the global, per-cluster, and per-sample level
- Metrics: stability and generalizability ARIs, consensus PAC, Gini, cross-entropy, and predictive accuracy
- Selection rules:
max,1se(one-standard-error), andquantile - Custom spectral clustering with self-tuning affinity (based on Zelnik-Manor & Perona, Self-Tuning Spectral Clustering, NeurIPS 2004)
- Plots: metric-over-k curves, consensus heatmaps, box plots, violin plots, and scatter plots
- Parallel resampling via joblib (
n_jobs)
Installation
CARVE requires Python 3.12 or newer.
pip install carve-validate
The distribution is named carve-validate; the import name is carve:
from carve import CARVE
From source (development)
git clone https://github.com/DataSlingers/CARVE.git
cd CARVE
pip install -e ".[dev]" # linting + testing
pip install -e ".[notebooks]" # Jupyter, Scanpy, scVI, etc.
Quick Start
from carve import CARVE
from sklearn.datasets import make_blobs
# Generate synthetic data
X, y_true = make_blobs(n_samples=500, n_features=10, centers=5, random_state=42)
# Fit CARVE
carve = CARVE(n_clusters=10, n_resamples=120, subsample_ratio=0.7, n_jobs=4)
carve.fit(X)
# Select best k and retrieve labels
k = carve.get_k(measure="generalizability", rule="1se")
labels = carve.get_labels(measure="generalizability", rule="1se")
print(f"Selected k={k}")
See notebooks/Tutorial.ipynb for a walkthrough, and notebooks/case_studies/ for real-world analyses on scRNA-seq and mass cytometry datasets.
Visualization
# Metric curves across k
carve.plot_metric_over_n_clusters(measure="stability", rule="1se")
# Consensus heatmap for the selected solution
carve.plot_consensus_matrix(measure="generalizability", rule="1se")
# Per-cluster stability violin plot
carve.plot_cluster_violin(source="gini", measure="generalizability", rule="1se")
# 2D scatter with score-encoded marker size and opacity
carve.plot_cluster_scatter(source="gini", measure="generalizability", rule="1se")
All plotting methods return a matplotlib Axes object and accept save and dpi parameters for export.
Citation
If you use CARVE in your research, please cite:
Wycik, K. R., Tang, T. M., Zikry, T. M., & Allen, G. I. (2026). CARVE: Cluster Analysis with Resampling for Validation and Exploration. Zenodo. https://doi.org/10.5281/zenodo.20417991
@software{wycik2026carve,
author = {Wycik, Kai R. and Tang, Tiffany M. and Zikry, Tarek M. and Allen, Genevera I.},
title = {{CARVE}: Cluster Analysis with Resampling for Validation and Exploration},
year = {2026},
publisher = {Zenodo},
doi = {10.5281/zenodo.20417991},
url = {https://doi.org/10.5281/zenodo.20417991}
}
Authors
- Kai R. Wycik — Columbia University
- Tiffany M. Tang — University of Notre Dame
- Tarek M. Zikry — UNC Chapel Hill
- Genevera I. Allen — Columbia University
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
This project uses Ruff for linting and formatting, and pytest for testing:
ruff check src/ # lint
ruff format src/ # format
pytest -v # run tests
Metadata
Release files for carve-validate 2.0.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 | Provenance | Actions |
|---|---|---|---|---|
| carve_validate-2.0.0.tar.gz | 171.7 kB | Without provenance | Details for carve_validate-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| carve_validate-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for carve_validate-2.0.0-py3-none-any.whl |
Total release size: 272.7 kB
Release files / carve_validate-2.0.0.tar.gz
| Download URL | carve_validate-2.0.0.tar.gz |
|---|---|
| Size | 171.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72c0535c9a9422f9f7ecce074cc480996db56ca9cd9218f1654bf6ffba254666
|
|
BLAKE2b-256 checksum How to use checksums |
44d4ed603019d298825ade9c814074166137b6fc9b12470c74dc9f6417226140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / carve_validate-2.0.0-py3-none-any.whl
| Download URL | carve_validate-2.0.0-py3-none-any.whl |
|---|---|
| Size | 101.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
967142979854e4523b2518ed521a1a2ee512a63116199eb6ab33e5fe41b62c3b
|
|
BLAKE2b-256 checksum How to use checksums |
3cd28401feba7c45d1efd88768544042dedf3fdf45da47650624f053edd3e1da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Security for carve-validate 2.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.