Stable low-FPR calibration for detection model scores across model releases.
Project description
FPRCal
Stable low-FPR calibration for detection model scores across model releases, with a fixed log-scale interpretability contract (0.5 = 0.1% FPR, 0.7 = 0.01%, 0.85 = 0.001%).
Why
Raw scores from ML detectors drift across model releases and are not comparable across detector categories. Downstream product rules break on every retrain. This package calibrates detector scores to FPR on benign traffic, then applies a fixed log-scale transform so every calibrated value has the same FPR meaning across model versions and detector categories.
Install
python -m pip install fprcal
Requires Python 3.12+, numpy, scikit-learn, joblib.
For an editable development install, use python -m pip install -e ".[dev]".
Usage
from fprcal import fit_calibration_pipeline
import joblib
pipeline = fit_calibration_pipeline(benign_scores, n_knots=10000)
joblib.dump(pipeline, "calibration.pkl")
# In production:
pipeline = joblib.load("calibration.pkl")
calibrated = pipeline.predict(raw_scores.reshape(-1, 1))
The first-pass FPR-to-threshold spline uses Filliben median-centered plotting
positions by default. Pass plotting_position="mean" to use the mean-centered
k/(n+1) positions instead.
Demo
Reproduce the evaluation figure on the Credit Card Fraud Detection dataset (OpenML, 284K rows, 0.172% positives):
# One-time: download the data, train both detectors, save holdout scores
python examples/generate_credit_card_roc.py
# Fit on the calibration subset and evaluate its held-out complement
python examples/calibration_demo.py
Writes examples/credit_card_validation.png. See examples/credit_card_readme.md for dataset provenance.
License
Apache License 2.0. See LICENSE.
Maintainers can find the release procedure in RELEASING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fprcal-0.1.0.tar.gz.
File metadata
- Download URL: fprcal-0.1.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5903e9b6e0df446ab277fa61fc48f73f57dafccb4662a9b2826868d471043ce0
|
|
| MD5 |
83be88962431828c9e459d3c2286d0bf
|
|
| BLAKE2b-256 |
2081a230fb456d7d7c32144b35da15beabf506c8456fe2c566992eaa80a8f39b
|
Provenance
The following attestation bundles were made for fprcal-0.1.0.tar.gz:
Publisher:
publish.yml on cisco-ai-defense/fpr-model-calibration
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fprcal-0.1.0.tar.gz -
Subject digest:
5903e9b6e0df446ab277fa61fc48f73f57dafccb4662a9b2826868d471043ce0 - Sigstore transparency entry: 2120570803
- Sigstore integration time:
-
Permalink:
cisco-ai-defense/fpr-model-calibration@d25ec277cf5fd7c077bc172e141b004ee4cc4941 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cisco-ai-defense
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d25ec277cf5fd7c077bc172e141b004ee4cc4941 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fprcal-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fprcal-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832bf9ba617e41dd3d12cd3ceda9473512424a77564cd7578e36524c30c0d7b7
|
|
| MD5 |
242451a324324050bd7872880dba2f4b
|
|
| BLAKE2b-256 |
8da9cf92e1a24821abeee825a06de35f1e29798253183e14d05cb258b1ea3554
|
Provenance
The following attestation bundles were made for fprcal-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cisco-ai-defense/fpr-model-calibration
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fprcal-0.1.0-py3-none-any.whl -
Subject digest:
832bf9ba617e41dd3d12cd3ceda9473512424a77564cd7578e36524c30c0d7b7 - Sigstore transparency entry: 2120570945
- Sigstore integration time:
-
Permalink:
cisco-ai-defense/fpr-model-calibration@d25ec277cf5fd7c077bc172e141b004ee4cc4941 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cisco-ai-defense
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d25ec277cf5fd7c077bc172e141b004ee4cc4941 -
Trigger Event:
release
-
Statement type: