labelfree
Compare and select anomaly detectors when you have no labeled anomalies.
Documentation · Metric guide · API reference · Examples
Choosing an anomaly detector usually means scoring it against labeled anomalies, which you rarely have.
Label-free metrics judge a detector by the structure of its scores, by the data
it was fitted on, or by how well it agrees with other candidates. labelfree
collects the published metrics behind one consistent API, each one tested
against its paper.
It works with any detector that produces one score per row, such as PyOD models, scikit-learn estimators or your own.
Installation
labelfree requires Python 3.12 or newer and depends only on NumPy, SciPy and scikit-learn.
pip install labelfree
Optional extras
| Extra | Adds |
|---|---|
examples |
PyOD, Optuna, pandas, matplotlib and oddball datasets for the example notebooks |
dev |
pytest, Ruff and pre-commit |
docs |
The documentation builder |
Quick start
Score the same unlabeled batch with several candidates, then rank them:
import numpy as np
from sklearn.covariance import EllipticEnvelope
from sklearn.ensemble import IsolationForest
from sklearn.svm import OneClassSVM
import labelfree as lf
rng = np.random.default_rng(0)
X = np.vstack([rng.normal(size=(500, 4)), rng.normal(4, 1, size=(25, 4))]) # unlabeled
candidates = {
"iforest": IsolationForest(random_state=0),
"iforest-64": IsolationForest(max_samples=64, random_state=0),
"ocsvm": OneClassSVM(nu=0.05),
"elliptic": EllipticEnvelope(random_state=0),
}
# scikit-learn's score_samples is higher for more normal points
scores = np.vstack([m.fit(X).score_samples(X) for m in candidates.values()])
agreement = lf.model_centrality_scores(scores, score_polarity="higher_is_normal")
separation = [
lf.score_cluster_metrics(s, contamination=0.05, score_polarity="higher_is_normal")[
"silhouette"
]
for s in scores
]
for name, a, s in zip(candidates, agreement, separation, strict=True):
print(f"{name:10} centrality={a:.2f} silhouette={s:.2f}") # higher is better
# iforest centrality=0.83 silhouette=0.76
# iforest-64 centrality=0.80 silhouette=0.80
# ocsvm centrality=0.77 silhouette=0.46
# elliptic centrality=0.86 silhouette=0.93
Every function that takes raw scores assumes that higher means more anomalous
unless you pass score_polarity="higher_is_normal".
Choose a metric
Pick by the evidence you have. The metric guide covers assumptions and directions.
| You have | Metrics |
|---|---|
| One score vector per candidate | score_cluster_metrics (silhouette, Calinski-Harabasz, Davies-Bouldin, Xie-Beni, R², RMSSTD, Hubert Γ, I-index, Dunn, S_Dbw) · relative_top_median_score, expected_anomaly_gap_score (AutoUAD) |
| Scores and the feature matrix | asi_score, asoi_score · laplacian_score · sireos_score · ireos_score, ireos_scores, ireos_significance |
| Scores from several candidates on the same rows | model_centrality_scores (MC, MCS, KNN) · udr_scores · hits_scores · ens_scores |
| Scores on normal validation data and on generated points | normalized_pseudo_discrepancy_score (AutoUAD) |
| Scores from repeated refits | ranking_stability_score |
| Scores on data and on uniform reference samples | excess_mass_curve, excess_mass_auc, mass_volume_curve, mass_volume_auc |
| Several metric rankings to combine | borda_scores, robust_borda_scores · unify_scores turns raw scores into outlier probabilities |
Sources
| Family | Paper |
|---|---|
| Score clusters | Nguyen et al. |
| ASI / ASOI | Mahmud et al. |
| AutoUAD | Dai and Fan |
| Laplacian Score | He et al. |
| IREOS, SIREOS | Marques et al. |
| Excess-Mass / Mass-Volume | Goix |
| Consensus | Ma et al. |
| Ranking stability | Perini et al. |
| Score unification | Kriegel et al. |
| Robust Borda | Goswami et al. |
Each implementation is tested against its paper and, where available, a transcription of the authors' code.
Examples
Two executed notebooks use real benchmark data and PyOD detectors. Install their dependencies with pip install "labelfree[examples]".
- Metric comparison computes every metric family for a pool of detectors, then uses the held-back labels to check how well each metric ranked them.
- Model selection tunes four detector families with Optuna on a label-free objective, picks one with robust Borda counting, and measures the pick on a labeled test split.
Scope
Citation
If you use labelfree in academic work, please cite the software:
@software{Hennhoefer_labelfree,
author = {Hennhöfer, Oliver},
title = {{labelfree: Label-free metrics for unsupervised anomaly detector evaluation}},
url = {https://github.com/OliverHennhoefer/label-free},
license = {MIT}
}
Please also cite the papers behind the metrics you use.
Project
Read the documentation, browse the changelog, or report a problem in the issue tracker. Contributions are welcome; start with the contributing guide. To develop locally:
python -m pip install -e ".[dev]"
pytest
labelfree is distributed under the MIT License.
Metadata
Release files for labelfree 1.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 | Provenance | Actions |
|---|---|---|---|---|
| labelfree-1.1.0.tar.gz | 225.3 kB | With provenance | Details for labelfree-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| labelfree-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for labelfree-1.1.0-py3-none-any.whl |
Total release size: 262.4 kB
Release files / labelfree-1.1.0.tar.gz
| Download URL | labelfree-1.1.0.tar.gz |
|---|---|
| Size | 225.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3d1a9d2cf36e3a68516f20cdf7a3ac7d18b0af4cbdcf2d270cb2b02ce82ab3f
|
|
BLAKE2b-256 checksum How to use checksums |
8fc21e4e2b4eef71b93e6be67a1c471620546d1bd7615e79520bacaf7b413db8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 22, 2026.
Transparency logRelease files / labelfree-1.1.0-py3-none-any.whl
| Download URL | labelfree-1.1.0-py3-none-any.whl |
|---|---|
| Size | 37.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acb5c71f0627e1aafb4fe1e7fa1aa544f8708a58ff8a6fd62cec0f9c503b72cf
|
|
BLAKE2b-256 checksum How to use checksums |
9f7bbb58d2c720068d8e528f64545897ba1873618a723cbf5489909f1a8a510f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 22, 2026.
Transparency logSecurity for labelfree 1.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for labelfree-1.1.0.tar.gz
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 Nov 22, 2026.
Transparency logA 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.