Skip to main content

uqcalibrate

Check whether a regression model's uncertainty is honest, and fix it when it is not.

A model that reports uncertainty makes a promise: "95% of true values will fall inside this band." uqcalibrate checks that promise on your test data, scores it with numbers that cannot be gamed by widening the band, and corrects a band that is off by a constant factor. It needs three arrays and NumPy, nothing else. Any model, any framework, any number of input features.

import uqcalibrate as uqc

report = uqc.evaluate(y_test, mean_test, std_test)
print(report)

The output below is real: 200 points from a seeded example whose model reports half the true spread (tests/conftest.py, honest_predictions, seed 1, scale=0.5).

uqcalibrate: 200 points, Gaussian bands
promised  delivered  plausible range  verdict        mean width  interval score
     50%      27.0%    21.3% - 33.5%  OVERCONFIDENT        0.81            3.34
     80%      45.5%    38.7% - 52.4%  OVERCONFIDENT        1.54            5.50
     90%      55.5%    48.6% - 62.2%  OVERCONFIDENT        1.98            7.73
     95%      65.0%    58.2% - 71.3%  OVERCONFIDENT        2.35           10.88
NLL 2.39
plausible range: 95% Wilson interval for the true coverage.
A wider range means weaker evidence.
OVERCONFIDENT: 95% promised, 65.0% delivered.

Install

pip install uqcalibrate

The latest code on main: pip install git+https://github.com/cgudumotu/uq.

Python 3.10 or newer. The only dependency is NumPy.

What you need

Three arrays, one value per test point:

Argument Meaning Shape
y the true values (n,)
mean the model's predictions (n,)
std the model's predictive standard deviation (the "give or take") (n,) or one number

If your model gives variances, pass np.sqrt(var). If it gives several predictions per point (an ensemble, Monte Carlo dropout, a Bayesian network), see Combining samples below.

Reading the report

  • promised: the level you asked for. "95%" means the band mean ± 1.96 · std.
  • delivered: the share of true values that fell inside that band.
  • plausible range: where the true coverage could be, given only n points (a 95% Wilson score interval). With 200 points an honest 95% band can deliver anywhere from about 92% to 98% by chance alone. A wider range means weaker evidence.
  • verdict: OVERCONFIDENT when even the top of the plausible range is below the promise (bands too narrow); UNDERCONFIDENT when even the bottom is above it (bands too wide); CONSISTENT when the promise lies inside the range, which means no evidence of a problem, not proof of calibration.
  • mean width: the average width of the band. Narrower is better only when coverage holds.
  • interval score: width plus a penalty for every miss (Gneiting & Raftery, 2007). Lower is better. Neither inflating nor shrinking the band improves it.
  • NLL: the Gaussian negative log-likelihood, a "surprise score". Lower is better. A vague model is charged for being vague, so this cannot be gamed by widening the band.

The headline is the verdict at 95%. In code, report.delivered and report.plausible_ranges hold the same numbers as fractions (0.65, not 65.0%), and report.to_dict() gives everything as plain Python types.

Fixing an overconfident model

If the bands are off by a constant factor, one number fixes them. Fit it on data the model has not been evaluated on, then confirm on separate test data:

s = uqc.fit_scaling(y_cal, mean_cal, std_cal)  # calibration split, not the test split
report = uqc.evaluate(y_test, mean_test, s * std_test)
print(report.headline)  # CONSISTENT: 95% promised, 94.0% delivered. No evidence of miscalibration.

fit_scaling cannot tell whether you reused the test split, so keep the splits separate.

Combining samples

An ensemble, Monte Carlo dropout or a Bayesian network gives several predictions per point. There is exactly one right way to turn them into one standard deviation, and it is the law of total variance: add the average noise variance to the variance of the means, then take one square root.

# means, noise_vars: shape (S, n) — S members or samples, n points
std = uqc.total_std(means, noise_vars)
mean = means.mean(axis=0)
report = uqc.evaluate(y_test, mean, std)

Standard deviations are never added, and a square root is never taken of a standard deviation. This package exists because a published thesis did both (see below).

Comparing models

Several models, one test set: compare scores each with evaluate, ranks the ones that report total uncertainty by their surprise score (never by coverage alone), and only names a winner when the lead is bigger than its own margin of error. Models without a noise term (plain Monte Carlo dropout, a Bayesian network without a variance output) go in epistemic_only: they are shown, but not ranked against models that report total uncertainty.

result = uqc.compare(
    y_test,
    {
        "simple neural network": (mean_a, s_a * std_a),
        "deep ensemble neural network": (mean_b, s_b * std_b),
        "deep operator neural network": (mean_c, s_c * std_c),
    },
    epistemic_only={"Monte Carlo dropout neural network": (mean_d, std_d)},
)
print(result)
print(result.best)   # a name, or None when the top two are too close to call
uqcalibrate: 3 models ranked, 1 epistemic-only, 60 points
rank  model                               95% delivered  mean width      NLL  verdict
   1  deep operator neural network                95.0%        4.52     1.55  CONSISTENT
   2  deep ensemble neural network                95.0%        5.03     1.55  CONSISTENT
   3  simple neural network                       73.3%        2.51     2.19  OVERCONFIDENT
Too close to call: the top two differ by 0.00 +/- 0.02 NLL per point.

Epistemic only (bands hold no noise term; not ranked)
   -  Monte Carlo dropout neural network          48.3%        1.76     3.69  OVERCONFIDENT

That output is real, from a seeded example (tests/conftest.py, honest_predictions, seed 3, 60 points): one honest set of predictions whose spread is scaled by 0.5, 1.0 and 0.9, plus a copy at 0.35 with no noise term. The labels are the thesis models' names, as train_and_compare will print them (coming in 0.2.0); here they are only labels, so the ranking says nothing about those architectures. The top two differ only by the 0.9 factor, which 60 points cannot tell apart, so no winner is named. Apply each model's own fit_scaling factor before comparing, and compare on data no factor was fitted on.

Many input features

The functions above never see your inputs X, so a model with 3 features or 300 works the same way. Predict, then evaluate.

Why this package exists

The author's master's thesis (Uncertainty Quantification in Deep Neural Networks, CSULB, 2024) computed a deep operator neural network's total standard deviation as √std(μ) + √mean(σ²) instead of √(var(μ) + mean(σ²)). The bands came out about 1.6× too wide, and the thesis's headline result (89.05% coverage of a "95%" band) followed from that error. Coverage alone could not catch it: wider bands always catch more points. ERRATA.md lists every affected table with its corrected numbers, and the reproduce/ folder rebuilds them with one command.

API

Function Returns Rule
evaluate(y, mean, std, levels=(0.5, 0.8, 0.9, 0.95)) CalibrationReport MATH-4, MATH-7
fit_scaling(y, mean, std) float factor, > 0 MATH-8
compare(y, predictions, epistemic_only=None, levels=...) ModelComparison MODEL-5a, MODEL-3
total_std(means, noise_vars) ndarray (n,) MATH-1
coverage(y, mean, std, level=0.95) float in [0, 1] MATH-3
gaussian_nll(y, mean, std) float MATH-5
interval_score(y, mean, std, level=0.95) float MATH-6

Every rule is written out in docs/constitution/MISSION.md, and every rule has a test that names it.

Coming in 0.2.0: uqcalibrate[torch], with the five neural-network architectures from the thesis and train_and_compare(X, y), which trains them, calibrates each on a held-out split and hands the results to compare.

License

MIT. See LICENSE.

Metadata

Release files for uqcalibrate 0.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 uqcalibrate 0.1.0
File Size Uploaded Provenance Actions
uqcalibrate-0.1.0.tar.gz 34.0 kB With provenance Details for uqcalibrate-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 54.3 kB

Release files / uqcalibrate-0.1.0.tar.gz

Download URL uqcalibrate-0.1.0.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7aeecb9c9e72da22741e1c6ce59e0c0430f3e8344bbc6dd2aa455034d9874edd
BLAKE2b-256 checksum
How to use checksums
b41c47862b28090adfff4c5600b0c9c34e056eee81f13a67e79ac8a66cb674e6
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 30, 2026.

Transparency log

Release files / uqcalibrate-0.1.0-py3-none-any.whl

Download URL uqcalibrate-0.1.0-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b19e72585fe52f0e691b9720d895e499a7e4a0e63b7731a5d4bc630dfec39af9
BLAKE2b-256 checksum
How to use checksums
99759847af38095caf4a9aeb53a628b90c250d3f87a9c378661515b5b070de31
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 30, 2026.

Transparency log

Security for uqcalibrate 0.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 uqcalibrate-0.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 30, 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

0.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