Skip to main content

Stable low-FPR calibration for detection model scores across model releases.

Project description

FPRCal

License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fprcal-0.1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fprcal-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

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

Hashes for fprcal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5903e9b6e0df446ab277fa61fc48f73f57dafccb4662a9b2826868d471043ce0
MD5 83be88962431828c9e459d3c2286d0bf
BLAKE2b-256 2081a230fb456d7d7c32144b35da15beabf506c8456fe2c566992eaa80a8f39b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fprcal-0.1.0.tar.gz:

Publisher: publish.yml on cisco-ai-defense/fpr-model-calibration

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for fprcal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 832bf9ba617e41dd3d12cd3ceda9473512424a77564cd7578e36524c30c0d7b7
MD5 242451a324324050bd7872880dba2f4b
BLAKE2b-256 8da9cf92e1a24821abeee825a06de35f1e29798253183e14d05cb258b1ea3554

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page