Skip to main content

nonconform

Turn anomaly scores into flags with a false-alarm rate you set.

PyPI version Supported Python versions Tests Code coverage Documentation License

Documentation · API Reference · Paper


A detector ranks points by how unusual they look but leaves the cutoff to you. The usual default, flagging the top 10% of scores, is a guess about how many anomalies there are. nonconform calibrates the scores of your existing detector against normal data, so the threshold follows from the error rate you can accept.

Works with     scikit-learn      PyOD      Custom AnomalyDetector protocol

The same Isolation Forest on seven benchmark datasets, with and without nonconform:

True anomalies and false alarms flagged on seven datasets: the detector alone flags about twice the real anomalies with 47 to 58 percent false; nonconform flags fewer, with 4 to 9 percent false

Mean of 20 random splits per benchmark dataset. The average false share stays under the 10% target on every dataset; where the detector barely separates anomalies (Mammography, Cardio), nonconform flags little rather than guess. The baseline trains on every row, nonconform holds some back for calibration. Reproduce with default_thresholds.py.

Installation

nonconform requires Python 3.11 or newer. Both discovery control and sequential monitoring are included in the core installation.

pip install nonconform
Optional extras
Extra Adds
pyod PyOD anomaly detectors
data oddball benchmark datasets and PyArrow support
fdr Streaming FDR procedures from online-fdr
probabilistic KDE-based probabilistic estimation and tuning
all Every optional feature

Quick start

Wrap a detector, fit it on normal data, and select anomalies at a target false discovery rate (FDR). The example loads a benchmark dataset, so it needs pip install "nonconform[data]":

from oddball import Dataset, load
from sklearn.ensemble import IsolationForest

from nonconform import ConformalDetector, Split

# Normal-only training data; a labelled test batch with 10% anomalies
x_train, x_test, y_test = load(Dataset.SHUTTLE, setup=True, seed=0)

alpha = 0.1  # target FDR: on average at most 10% of flags are false
detector = ConformalDetector(
    detector=IsolationForest(random_state=0),
    strategy=Split(n_calib=int(len(x_test) / alpha)),  # see the sizing rule below
    seed=0,
).fit(x_train)

flagged = detector.select(x_test, alpha=alpha)  # Boolean mask
hits = int(y_test[flagged].sum())
print(f"Flagged {flagged.sum()} of {len(x_test)}, {hits} true anomalies")
# Flagged 105 of 1000, 95 true anomalies

The conformal p-values behind the mask stay available in detector.last_result. Any PyOD model, a recognized scikit-learn estimator, or a custom detector works in place of IsolationForest.

Set a score threshold

If the requirement is "flag no more than 5% of normal points", certify a raw-score threshold instead of targeting an FDR:

certificate = detector.fpr_bounds(confidence=0.95)
selected = certificate.select(detector.score_samples(x_test), target_fpr=0.05)
print(f"Certified threshold: {certificate.threshold_for(0.05)}")

With 95% probability over the calibration draw, the threshold flags at most 5% of future normal points. Calibration and future normal scores must be i.i.d.; targets below the certificate's band floor (about 3.85% for 1,000 calibration scores at 95% confidence) give an infinite threshold. See raw-score false-alarm control.

Monitor a stream

A fitted Split detector can start a sequential monitor that raises an alarm when the data stops looking like the calibration set.

Monitor a stream for change
import numpy as np
from sklearn.ensemble import IsolationForest

from nonconform import ConformalDetector, Split
from nonconform.martingales import AlarmConfig, SimpleJumperMartingale
from nonconform.monitoring import ExchangeabilityMonitor

rng = np.random.default_rng(42)
x_train = rng.normal(size=(1_000, 2))

detector = ConformalDetector(
    detector=IsolationForest(random_state=42),
    strategy=Split(n_calib=0.3),
    seed=42,
).fit(x_train)

alpha = 0.05
monitor = ExchangeabilityMonitor.from_split_detector(
    detector,
    martingale=SimpleJumperMartingale(
        alarm_config=AlarmConfig(restarted_ville_threshold=1 / alpha)
    ),
    seed=42,
)

# Stable observations followed by a distribution shift
x_stream = np.vstack([
    rng.normal(size=(50, 2)),
    rng.normal(loc=3.0, size=(50, 2)),
])

for x_t in x_stream:
    state = monitor.update(x_t)
    if "restarted_ville" in state.triggered_alarms:
        print(f"Change alarm at step {state.evidence_step}")
        break

Under the sequential validity assumptions, the restarted Ville alarm at 1 / alpha bounds the probability of ever raising a false alarm on one stream. See the sequential monitoring guide.

Choose a workflow

Goal Start with
Calibrate and select anomalies in a batch Split and select(...)
Set a per-inlier raw-score false-alarm target fpr_bounds(...) and FPR certificates
Aggregate evidence across random splits DerandomizedSplits and e-BH
Monitor a stream for change Exchangeability martingales
Reuse more data for fitting and calibration CrossValidation or JackknifeBootstrap
Account for covariate shift Weighted conformal inference
Calibrate groups with different normal behavior Group-conditional (Mondrian) p-values
Certify realized FDP across p-value thresholds fdp_bounds(...) and FDP certificates
Bring a custom or third-party detector Detector compatibility

Coding agents

An agent skill teaches coding agents to use nonconform without overclaiming. Install it in Claude Code (/plugin marketplace add OliverHennhoefer/nonconform, then /plugin install nonconform@nonconform) or Codex (codex plugin marketplace add OliverHennhoefer/nonconform, then codex plugin add nonconform@nonconform).

Statistical scope

nonconform calibrates detector scores; it cannot make an unsuitable detector or a mismatched calibration set valid. Handle spatial or temporal dependence before relying on exchangeability. Read the guides to FDR control and sequential monitoring before applying a guarantee to a new problem.

Citation

If you use nonconform in academic work, please cite the accompanying paper:

@inproceedings{Hennhoefer2026,
author = {Hennhöfer, Oliver and Kirsch, Maximilian and Preisach, Christine},
booktitle = {Proceedings of the Fifteenth Symposium on Conformal and Probabilistic Prediction with Applications},
pages = {613--632},
publisher = {PMLR},
title = {{Conformal Anomaly Detection in Python: Moving Beyond Heuristic Thresholds with nonconform}},
url = {https://proceedings.mlr.press/v329/hennhofer26a.html},
year = {2026}
}

Project

Read the documentation, browse the changelog, or report a problem in the issue tracker. Contributions are welcome; start with the contributing guide. nonconform is distributed under the BSD 3-Clause License.

Funding acknowledgement

Metadata

Release files for nonconform 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonconform 2.1.0
File Size Uploaded Provenance Actions
nonconform-2.1.0.tar.gz 113.9 kB With provenance Details for nonconform-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonconform 2.1.0
File Interpreter ABI Platform Actions
nonconform-2.1.0-py3-none-any.whl Python 3 none any Details for nonconform-2.1.0-py3-none-any.whl

Total release size: 233.1 kB

Release files / nonconform-2.1.0.tar.gz

Download URL nonconform-2.1.0.tar.gz
Size 113.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5a3875a5913bf21f7e29f1592c666654abb5a27ab00757ad390f8ecf8f3864d1
BLAKE2b-256 checksum
How to use checksums
b52ab1747bc790c4ea3f49bd70f78258ba6a8f8ffe7ae351351be9221d08daaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 20, 2026.

Transparency log

Release files / nonconform-2.1.0-py3-none-any.whl

Download URL nonconform-2.1.0-py3-none-any.whl
Size 119.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b90d25ce916af00a7440b08926aae42693dce2d653c5f12deaf77472fce3db95
BLAKE2b-256 checksum
How to use checksums
c0a2a824365b80f3a3700cc833412ecec4ea98e75dbe5ba8b19112bc8a965674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 20, 2026.

Transparency log

Security for nonconform 2.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.

Select from 2 files

Attestation for nonconform-2.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 20, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page