Skip to main content

fbcert

Tell from a batch of scores whether the label-shift likelihood puts its optimum above a chosen floor.

Pin Ni, Angela Altmeier and Christian Fisch. Certify Before Recalibrating: Exact Support Tests for Label-Shift EM in Rare Web Streams. WSDM '27, to appear. DOI 10.1145/3862322.3863596 · Mathematical supplement · Empirical supplement

A classifier can rank cases well and still predict the wrong number of events. When prevalence changes, label-shift EM estimates a new rate from the scores. For rare events, that estimate can fall to zero. Given the source prevalence and a minimum rate you care about, one pass over the scores determines which side of that floor the likelihood favors.

Installation

Install the library and its command line with pip.

pip install fbcert

For the study programs and example files, install from the repository checkout.

git clone https://github.com/MaxwellNi/fbcert
cd fbcert
pip install .

The library depends on NumPy. To draw the paper's figures, add Matplotlib and install the figure fonts.

pip install '.[figures]'

Install reproduction for the fitting programs. The recurrent comparator also needs recurrent. The comparison with the abstention package needs that package and the quantifiers extra. The version table lists the versions used in the study and in the rebuild.

Quick start

The source event rate was 1% and the workload floor is 0.5%. The CSV needs a header named score and one probability per row in that column.

csv=$(mktemp)
printf '%s\n' score 0.001 0.002 0.004 0.007 0.013 0.029 > "$csv"
fbcert "$csv" --source-prior 0.01 --floor 0.005
rm "$csv"

The command prints this JSON report.

{
  "n": 6,
  "source_prior": 0.01,
  "mu": 0.9422780735594726,
  "decision": {
    "floor": 0.005,
    "support": -0.062555139576431,
    "side": "below",
    "numerical_tolerance": 1e-12
  },
  "optimum": {
    "kind": "zero",
    "lower": 0.0,
    "upper": 0.0,
    "unique": true
  },
  "em": {
    "prevalence": 1.6131924435684172e-07,
    "iterations": 183,
    "converged": true,
    "movement": 9.882098080347236e-09,
    "tolerance": 1e-08,
    "max_iter": 1000
  }
}

The negative slope at the floor puts the optimum below 0.5%. The EM-map slope at zero, mu, equals the mean relative odds. In exact arithmetic a nonflat likelihood has its optimum at zero whenever this mean is at most one. If the reported mean rounds to one, read optimum.kind for the boundary decision. When rounding prevents a definite sign at the floor, the command reports decision.side as unresolved. The function fbcert.exact_support evaluates the same slope in exact rational arithmetic.

from fbcert import BinaryBatch

scores = [0.001, 0.002, 0.004, 0.007, 0.013, 0.029]
batch = BinaryBatch(scores, source_prior=0.01)
print(batch.mu, batch.decide(floor=0.005).side, batch.optimum().kind)
# 0.9422780735594726 below zero

For several classes, an excluded class can still improve a fit. Here the second class has zero target weight. The returned step gives it positive weight and supplies a lower bound on the gain in log likelihood.

from fbcert import MulticlassBatch

scores = [[0.20, 0.50, 0.30], [0.10, 0.60, 0.30]]
batch = MulticlassBatch(scores, source_prior=[0.4, 0.3, 0.3])
q = [0.5, 0.0, 0.5]
print(batch.diagnostics(q).global_gap_upper_bound)
print(batch.escape(q, excluded=1).improvement_lower_bound)
# 3.4222222222222243
# 0.23113207547169537

For examples that read the scores from the CSV files in the repository, see the reproduction guide.

Reproducing the paper

Task Command from the repository root Inputs and runtime
Check all 1,335 registered claims python -m scripts.check_claims Bundled records, seconds
Run the tests python -m unittest discover -s tests NumPy for the core tests. Fitting tests need reproduction. Add recurrent for the recurrent tests, or quantifiers and the abstention package for the comparison tests.
Draw the three figures python -m scripts.draw_figures Bundled records, Matplotlib and Linux Libertine, seconds
Rebuild from the raw archives Follow the commands in the reproduction guide below. Use python -m scripts.study_pipeline --list-stages to preview the stages. GLEIF, SEC Form D and Kickstarter archives. About 8 hours elapsed and 25 CPU-hours in the reference run.

Starting from the raw archives on Intel Xeon Gold 6132 processors, the study programs regenerated 54 of 56 records in full. A further record combines three measured checks with three observations from data collection. The last record supplies the study settings.

Of the 1,331 values registered for that run, 1,315 matched at printed precision. Fourteen differences came from the logistic comparator, and two were numerical residuals within their stated bounds. On the pooled registry development data, the four predictors kept the same ordering by PR-AUC, log loss and Brier score. The reproduction guide gives the commands, timings and precision criteria.

Repository layout

Path Contents
fbcert/, examples/ Library, command line and sample score batches
records/, claims/ Numerical results, their field definitions and the expressions for printed values
scripts/ Obtain and verify source archives, evaluate predictions, rebuild the study, check the published values, draw the figures and replay the result tables
data/, experiments/ Input manifests and fitting programs
paper/ Mathematical and empirical supplements
tests/, docs/ Test suite, reproduction guide and data guide

Data

The study uses GLEIF registry publications, SEC Form D filings and a Web Robots Kickstarter snapshot. The manifests identify the source files. Obtain the raw files from the sources listed in the data guide. The repository contains aggregate results and model-fitting code.

Scope

The test locates the likelihood optimum for the batch. One registry estimate passed at a floor of half the mean of the last three observed rates and still overestimated the event rate by 688%. In the paper's replay, acting on the test did not improve prediction. Files from the first four days of the registry holdout had been parsed for counts, including event counts, before the design was final.

Citation

@inproceedings{ni2027certify,
  author    = {Ni, Pin and Altmeier, Angela and Fisch, Christian},
  title     = {Certify Before Recalibrating: Exact Support Tests for Label-Shift {EM} in Rare Web Streams},
  booktitle = {Proceedings of the Twentieth ACM International Conference on Web Search and Data Mining},
  year      = {2027},
  doi       = {10.1145/3862322.3863596},
  publisher = {Association for Computing Machinery}
}

License

This repository is released under the MIT License. Source data remain subject to their providers' terms.

Metadata

Release files for fbcert 1.0.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 fbcert 1.0.0
File Size Uploaded Provenance Actions
fbcert-1.0.0.tar.gz 20.8 kB Without provenance Details for fbcert-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 44.1 kB

Release files / fbcert-1.0.0.tar.gz

Download URL fbcert-1.0.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fdbf081bcab2ae6a3ba8a2633d76ca773d042ecf3891ca850a83de9cf91d8595
BLAKE2b-256 checksum
How to use checksums
e08f92f093762839e95ed7e4405980517251339a55f1fb482b333c11516301ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / fbcert-1.0.0-py3-none-any.whl

Download URL fbcert-1.0.0-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4214f8ff2acff5ff6276767f6d0b4ea74d634d4af2e05394b09d4c172f1eb30b
BLAKE2b-256 checksum
How to use checksums
6834bf752a159c866c9a8f231426aa79d5579061f24f7a0624335e14380882dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for fbcert 1.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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No 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