API: calibrators¶
base
¶
BaseCalibrator: the common fit / predict_proba / interpret contract.
UnattainableTargetError
¶
Bases: ValueError
The requested calibrated interval does not intersect the calibrator's
output range (or was emptied by buffer_logit). Raised instead of
silently clamping — spec §10.
BaseCalibrator
¶
Bases: ABC
Common contract for all probcal calibrators.
Subclasses implement _fit (estimation on validated arrays),
_predict (the fitted map on clipped scores), and interpret.
Everything else — validation, sklearn-style parameter handling without an
sklearn import, the 2-D probability helper — lives here.
| ATTRIBUTE | DESCRIPTION |
|---|---|
is_monotone_ |
Whether the fitted map is guaranteed non-decreasing. Class-level
default
TYPE:
|
fitted_ |
Set by :meth:
TYPE:
|
affine_logit_coeffs_
property
¶
affine_logit_coeffs_: tuple[float, float] | None
Coefficients (a, b) of logit g(s) = a * logit(s) + b, if affine.
None for calibrators that are not affine on the logit scale.
Consumed by the attribution adjustment (spec §9).
fit
¶
fit(s: object, y: object, sample_weight: object = None) -> Self
Fit the calibration map on scores and binary outcomes.
| PARAMETER | DESCRIPTION |
|---|---|
s
|
Raw scores/probabilities in
TYPE:
|
y
|
Binary outcomes in
TYPE:
|
sample_weight
|
Positive observation weights.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The fitted calibrator. |
Source code in src/probcal/base.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
predict_proba
¶
predict_proba(s: object) -> ndarray
Calibrated probabilities P(y = 1) for new scores.
| PARAMETER | DESCRIPTION |
|---|---|
s
|
Raw scores/probabilities in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
numpy.ndarray of shape (n,)
|
Calibrated probabilities. |
Source code in src/probcal/base.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
predict_proba_2d
¶
predict_proba_2d(s: object) -> ndarray
Sklearn-style (n, 2) probability matrix [P(y=0), P(y=1)].
Source code in src/probcal/base.py
94 95 96 97 | |
interpret
abstractmethod
¶
interpret() -> Interpretation
Fitted parameters with a plain-language, domain-aware reading.
Source code in src/probcal/base.py
109 110 111 | |
interval_inverse
¶
interval_inverse(lo: float, hi: float, *, space: str = 'probability', buffer_logit: float = 0.0) -> tuple[float, float]
Generalized-inverse preimage (raw_lo, raw_hi) of a calibrated interval.
For a non-decreasing fitted map g:
raw_lo = inf{s : g(s) >= lo} and raw_hi = sup{s : g(s) <= hi}.
| PARAMETER | DESCRIPTION |
|---|---|
lo
|
Calibrated-probability bounds;
TYPE:
|
hi
|
Calibrated-probability bounds;
TYPE:
|
space
|
Scale of the returned raw bounds.
TYPE:
|
buffer_logit
|
Shrink the calibrated interval by this margin in logit space before inverting — robustness against future recalibration drift (a central-tendency update of magnitude <= buffer cannot invalidate the result).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
UnattainableTargetError
|
If the (buffered) interval does not intersect the output range — never silently clamped. |
NotImplementedError
|
For non-monotone calibrators ( |
Source code in src/probcal/base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
get_params
¶
get_params(deep: bool = True) -> dict[str, object]
Constructor parameters as a dict (manual sklearn-compatible clone info).
Source code in src/probcal/base.py
231 232 233 234 235 236 237 238 | |
set_params
¶
set_params(**params: object) -> Self
Set constructor parameters; unknown names raise ValueError.
Source code in src/probcal/base.py
240 241 242 243 244 245 246 247 248 249 250 | |
parametric
¶
Parametric calibrators: Platt, temperature, and beta calibration.
Theory, derivations, and parameter interpretation: docs/concepts/methods-parametric.md.
References
Platt (1999); Lin, Lin & Weng (2007); Guo et al. (2017); Kull, Silva Filho & Flach (2017, AISTATS and EJS) — full records in the documentation.
PlattCalibrator
¶
Bases: BaseCalibrator
Logistic recalibration on the logit scale (Platt scaling).
Fits logit g(s) = a * logit(s) + b by IRLS with Lin–Lin–Weng smoothed
targets (N+ + 1)/(N+ + 2) and 1/(N- + 2) for stability on small
samples. The identity map is (a, b) = (1, 0).
| ATTRIBUTE | DESCRIPTION |
|---|---|
a_ |
Fitted slope — spread correction:
TYPE:
|
b_ |
Fitted intercept — calibration-in-the-large shift in log-odds.
TYPE:
|
References
Platt (1999); Lin, Lin & Weng (2007). The logistic family fitted on raw SVM outputs (Platt's original setting) does not contain the identity; on logits it does — see the parametric-methods chapter.
affine_logit_coeffs_
property
¶
affine_logit_coeffs_: tuple[float, float] | None
(a, b): Platt scaling is affine on the logit scale.
interpret
¶
interpret() -> Interpretation
Read the fitted slope and intercept against the identity (1, 0).
Source code in src/probcal/parametric.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
TemperatureCalibrator
¶
Bases: BaseCalibrator
Temperature scaling: g(s) = sigma(logit(s) / T).
T minimizes the calibration-set negative log-likelihood via a
safeguarded 1-D Newton iteration (bisection fallback) on u = 1/T.
| ATTRIBUTE | DESCRIPTION |
|---|---|
T_ |
Fitted temperature.
TYPE:
|
References
Guo, Pleiss, Sun & Weinberger (2017).
affine_logit_coeffs_
property
¶
affine_logit_coeffs_: tuple[float, float] | None
(1/T, 0): temperature scaling is affine on the logit scale.
interpret
¶
interpret() -> Interpretation
Read the fitted temperature against the identity T = 1.
Source code in src/probcal/parametric.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
BetaCalibrator
¶
BetaCalibrator(variant: str = 'abm')
Bases: BaseCalibrator
Beta calibration: logit g(s) = a·ln s − b·ln(1 − s) + c.
Variants (spec §6; DECISIONS entry 27): "abm" fits (a, b, c);
"ab" ties a = b (equivalent to Platt scaling on logits); "a"
additionally fixes c = 0 (a single-parameter map, the temperature
family in a different parameterization). The monotonicity constraint
a, b >= 0 is enforced by the betacal refit strategy: a negative
exponent drops its feature and refits.
| ATTRIBUTE | DESCRIPTION |
|---|---|
a_ |
Sensitivity near
TYPE:
|
b_ |
Sensitivity near
TYPE:
|
c_ |
Base-rate shift in log-odds.
TYPE:
|
constraint_active_ |
Whether the
TYPE:
|
References
Kull, Silva Filho & Flach (2017), AISTATS 54 and EJS 11(2). The identity
is (a, b, c) = (1, 1, 0): beta calibration cannot un-calibrate an
already calibrated model. a != b captures asymmetric tail distortion;
temperature is the special case a = b = 1/T, c = 0.
Source code in src/probcal/parametric.py
210 211 | |
affine_logit_coeffs_
property
¶
affine_logit_coeffs_: tuple[float, float] | None
(a, c) for the tied variants; None for "abm".
With a = b the map reduces to logit g = a * logit(s) + c,
which is affine on the logit scale; the full three-parameter map
is not (see the shap-calibration chapter).
interpret
¶
interpret() -> Interpretation
Read the fitted exponents and intercept against the identity (1, 1, 0).
Source code in src/probcal/parametric.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
isotonic
¶
Isotonic calibrators: PAVA-based isotonic and centered isotonic regression (CIR).
Theory and worked example: docs/concepts/methods-nonparametric.md.
References
Barlow, Bartholomew, Bremner & Brunk (1972); Zadrozny & Elkan (2002); Oron & Flournoy (2017) — full records in the documentation.
IsotonicCalibrator
¶
IsotonicCalibrator(interpolation: str = 'none')
Bases: BaseCalibrator
Isotonic calibration: the PAVA step function.
Fits the least-squares non-decreasing map of outcomes on scores. The
fitted map is a right-continuous step function with one level per pooled
block; scores outside the calibration range clamp to the first/last
level. interpolation="linear" instead joins block midpoints, removing
the discontinuities.
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_blocks_ |
Number of pooled blocks — the effective complexity estimated from the data.
TYPE:
|
block_mean_ |
Event rate of each pooled block (the step levels).
TYPE:
|
block_first_s_, block_last_s_ |
Score range covered by each block.
TYPE:
|
block_center_s_ |
Weight-centered score coordinate of each block (used by CIR).
TYPE:
|
References
Barlow et al. (1972) for PAVA; Zadrozny & Elkan (2002) for its use in classifier calibration.
Source code in src/probcal/isotonic.py
57 58 | |
interpret
¶
interpret() -> Interpretation
Read the block structure as effective complexity and local event rates.
Source code in src/probcal/isotonic.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
CenteredIsotonicCalibrator
¶
CenteredIsotonicCalibrator()
Bases: IsotonicCalibrator
Centered isotonic regression (CIR): strictly increasing where data permit.
Post-processes the PAVA solution by collapsing each block to its weight-centered score coordinate and interpolating linearly through the points (Oron & Flournoy, 2017). Removes the step function's tied predictions — preferred when downstream ranking must be strict.
References
Oron & Flournoy (2017).
Source code in src/probcal/isotonic.py
144 145 | |
interpret
¶
interpret() -> Interpretation
Isotonic reading plus the strictness property CIR adds.
Source code in src/probcal/isotonic.py
166 167 168 169 170 171 172 173 174 175 176 177 178 | |
binning
¶
Binning calibrators: histogram binning and scaling-binning.
Theory: docs/concepts/methods-nonparametric.md.
References
Zadrozny & Elkan (2001); Kumar, Liang & Ma (2019) — full records in the documentation.
HistogramBinningCalibrator
¶
HistogramBinningCalibrator(n_bins: int = 10, strategy: str = 'mass', shrinkage: str | None = 'jeffreys')
Bases: BaseCalibrator
Histogram binning: per-bin event rates with optional Jeffreys shrinkage.
| PARAMETER | DESCRIPTION |
|---|---|
n_bins
|
Requested number of bins
TYPE:
|
strategy
|
TYPE:
|
shrinkage
|
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
bin_rate_ |
Calibrated value per (non-degenerate) bin.
TYPE:
|
is_monotone_ |
Computed after fitting: binning does not assume monotonicity, so the flag reports whether the fitted rates happen to be non-decreasing.
TYPE:
|
References
Zadrozny & Elkan (2001).
Source code in src/probcal/binning.py
52 53 54 55 56 57 | |
interpret
¶
interpret() -> Interpretation
Read bin rates as local event frequencies and B as the complexity dial.
Source code in src/probcal/binning.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
ScalingBinningCalibrator
¶
ScalingBinningCalibrator(n_bins: int = 10)
Bases: BaseCalibrator
Scaling-binning (Kumar–Liang–Ma): Platt stage, then bin the fitted values.
Fits Platt scaling first, then forms equal-mass bins of the fitted function values and outputs the mean of the fitted values within each bin. Achieves measurable calibration error with O(1/eps^2 + B) samples versus O(B/eps^2) for histogram binning.
References
Kumar, Liang & Ma (2019).
Source code in src/probcal/binning.py
143 144 | |
interpret
¶
interpret() -> Interpretation
Two-stage reading: Platt map, then the error-measurability discretization.
Source code in src/probcal/binning.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
bayesian
¶
Bayesian-ensemble calibrators: BBQ and ENIR.
Theory: docs/concepts/methods-nonparametric.md.
References
Naeini, Cooper & Hauskrecht (2015); Naeini & Cooper (2016); Tibshirani, Hoefling & Tibshirani (2011) — full records in the documentation.
BBQCalibrator
¶
BBQCalibrator(min_bins: int | None = None, max_bins: int | None = None)
Bases: BaseCalibrator
Bayesian Binning into Quantiles: model averaging over equal-mass binnings.
Considers equal-mass binning models over a range of bin counts, scores each by its Beta-Binomial log marginal likelihood under a per-bin Jeffreys Beta(1/2, 1/2) prior, and predicts with the posterior-weighted average of the models' (posterior-mean) bin rates.
| PARAMETER | DESCRIPTION |
|---|---|
min_bins
|
Range of candidate bin counts; defaults to
TYPE:
|
max_bins
|
Range of candidate bin counts; defaults to
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
bins_grid_ |
Candidate bin counts.
TYPE:
|
weights_ |
Posterior weights over the candidates (sum to 1).
TYPE:
|
References
Naeini, Cooper & Hauskrecht (2015).
Source code in src/probcal/bayesian.py
48 49 50 | |
interpret
¶
interpret() -> Interpretation
Read the posterior weights as uncertainty about the data's resolution.
Source code in src/probcal/bayesian.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
ENIRCalibrator
¶
Bases: BaseCalibrator
Ensemble of near-isotonic regressions (ENIR).
Computes the full nearly-isotonic solution path (modified PAVA of
Tibshirani, Hoefling & Tibshirani, 2011) from the raw data (lambda = 0)
to the fully isotonic fit, then averages the breakpoint solutions with
BIC weights. The combined map may be non-monotone: is_monotone_ is
False and consumers requiring order preservation should prefer a
monotone calibrator.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path_lambdas_ |
Breakpoints of the penalty parameter, starting at 0.
TYPE:
|
path_solutions_ |
Fitted values on the tie-aggregated score grid at each breakpoint.
TYPE:
|
weights_ |
BIC weights over the path solutions (sum to 1).
TYPE:
|
References
Naeini & Cooper (2016); Tibshirani, Hoefling & Tibshirani (2011).
interpret
¶
interpret() -> Interpretation
Read the path length and BIC weights; warn about non-monotonicity.
Source code in src/probcal/bayesian.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
vennabers
¶
Venn–Abers calibrators: inductive (IVAP) and cross (CVAP).
Theory, validity guarantee scope, and the scalarization caveat:
docs/concepts/methods-distribution-free.md. The guarantee attaches to the
interval returned by :meth:VennAbersCalibrator.predict_interval; the scalar
from predict_proba is the log-loss-minimax merger and is not itself covered
by the validity theorem.
References
Vovk & Petej (2014) — full record in the documentation.
VennAbersCalibrator
¶
Bases: BaseCalibrator
Inductive Venn–Abers predictor (IVAP).
For a query score, two isotonic fits on the calibration set augmented
with the query labeled 0 (resp. 1) yield the interval [p0, p1];
predict_proba scalarizes it as p1 / (1 - p0 + p1).
Batch prediction deduplicates query scores and runs two PAVA fits per unique score (DECISIONS entry: the O((n+m)log(n+m)) precomputation of Vovk & Petej is a planned optimization, not yet implemented).
predict_interval
¶
predict_interval(s: object) -> ndarray
Venn–Abers intervals [p0, p1] for new scores.
| PARAMETER | DESCRIPTION |
|---|---|
s
|
Raw scores/probabilities in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
numpy.ndarray of shape (n, 2)
|
Columns |
Source code in src/probcal/vennabers.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
interpret
¶
interpret() -> Interpretation
Report interval widths over the calibration scores — where to trust the map.
Source code in src/probcal/vennabers.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
CrossVennAbersCalibrator
¶
CrossVennAbersCalibrator(cv: int = 5, random_state: int = 42)
Bases: BaseCalibrator
Cross Venn–Abers predictor (CVAP): fold-wise IVAPs, geometric-mean merge.
Splits the calibration data into cv stratified folds; each fold's
IVAP is fitted on the remaining folds. The scalar output merges the
fold-wise pairs by the log-loss rule of Vovk & Petej:
GM(p1) / (GM(1 - p0) + GM(p1)). predict_interval returns the
conservative envelope [min_k p0_k, max_k p1_k] (DECISIONS entry —
the paper defines only the scalar merge).
Source code in src/probcal/vennabers.py
110 111 112 | |
predict_interval
¶
predict_interval(s: object) -> ndarray
Conservative fold envelope [min_k p0_k, max_k p1_k] (see class docs).
Source code in src/probcal/vennabers.py
140 141 142 143 144 145 146 147 | |
interpret
¶
interpret() -> Interpretation
Report fold count and envelope widths over a probe grid.
Source code in src/probcal/vennabers.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
spline
¶
Spline calibrator: penalized natural cubic splines on the logit scale.
Theory: docs/concepts/methods-nonparametric.md.
References
Lucena (2018); Hastie, Tibshirani & Friedman (2009), §5.2.1 — full records in the documentation.
SplineCalibrator
¶
SplineCalibrator(n_knots: int | None = None, lambdas: object = None, cv: int = 5, random_state: int = 42)
Bases: BaseCalibrator
Natural cubic spline calibration on the logit scale.
Models logit g(s) = sum_k theta_k N_k(logit s) with the natural cubic
basis (linear beyond the boundary knots), fitted by penalized IRLS with a
second-difference roughness penalty. The penalty weight is chosen by
K-fold cross-validated log loss within the calibration set.
| PARAMETER | DESCRIPTION |
|---|---|
n_knots
|
Number of knots (placed at equally spaced quantiles of the logit
scores); defaults to
TYPE:
|
lambdas
|
Candidate penalty weights; defaults to
TYPE:
|
cv
|
Inner fold count for the lambda search.
TYPE:
|
random_state
|
Seed for the stratified fold assignment.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
lambda_ |
Selected penalty weight.
TYPE:
|
edof_ |
Effective degrees of freedom — trace of the smoother matrix at the fitted solution; the honest complexity measure.
TYPE:
|
n_knots_ |
Number of knots actually used.
TYPE:
|
is_monotone_ |
Checked on a dense grid after fitting; the penalty does not enforce monotonicity, and a rare non-monotone fit is flagged with a warning.
TYPE:
|
References
Lucena (2018); Hastie, Tibshirani & Friedman (2009), §5.2.1.
Source code in src/probcal/spline.py
95 96 97 98 99 100 101 102 103 104 105 | |
interpret
¶
interpret() -> Interpretation
Read effective degrees of freedom as the honest complexity measure.
Source code in src/probcal/spline.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |