score= when constructing a method, or
leave it out to take the method’s default. Each concrete score carries a kind
tag ("absolute", "signed", "quantile"), which is what lets a configured
method survive model_validate(model_dump()).
A custom score subclasses ScoreFunction (or one of the built-ins) and declares
its own tag, e.g. kind: Literal["scaled"] = "scaled". Subclassing a built-in
without declaring a new tag raises TypeError when the class is defined,
because the score would otherwise reload as its parent. To reload a dumped
method holding a custom score, import the module that defines the score first.
AbsoluteResidual
Bases: ScoreFunction
Nonconformity score defined as the absolute residual |truth - prediction|.
This is the simplest and most widely used score function in conformal
prediction. It produces symmetric intervals around the point forecast.
AbsoluteResidual.CONSUMES_QUANTILES
AbsoluteResidual.fit
fit before the first call to :meth:score on the
calibration data, so implementations can assume that prediction and
truth are the full calibration arrays.
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) truth : Forecast, shape (n_series, n_samples, horizon)AbsoluteResidual.from_kind
kind tag names.
Parameters
value : dict A dumped score, carrying akind key.
Returns
ScoreFunctionRaises
ValueError Ifkind is missing or names no registered score. The module
defining a custom score must be imported before loading it.
AbsoluteResidual.invert
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) score_threshold : NDArray Either scalar, shape (n_series,), or shape (n_series, horizon). Broadcast againstprediction along its last two axes.
Returns
Interval, shape (n_series, n_samples, horizon, 2) Last axis is (lower, upper).AbsoluteResidual.kind
AbsoluteResidual.score
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) truth : Forecast, shape (n_series, n_samples, horizon)Returns
scores : NDArray, shape (n_series, n_samples, horizon)SignedResidual
Bases: ScoreFunction
Nonconformity score defined as the signed residual truth - prediction.
Unlike :class:AbsoluteResidual, this score preserves directional
information. Positive scores indicate truth was above prediction;
negative scores indicate truth was below. Used by methods that produce
asymmetric intervals around the point forecast (e.g. SPCI).
SignedResidual.CONSUMES_QUANTILES
SignedResidual.fit
fit before the first call to :meth:score on the
calibration data, so implementations can assume that prediction and
truth are the full calibration arrays.
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) truth : Forecast, shape (n_series, n_samples, horizon)SignedResidual.from_kind
kind tag names.
Parameters
value : dict A dumped score, carrying akind key.
Returns
ScoreFunctionRaises
ValueError Ifkind is missing or names no registered score. The module
defining a custom score must be imported before loading it.
SignedResidual.invert
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) score_threshold : NDArray, shape (n_series, horizon, 2) or (n_series, n_samples, horizon, 2) For each cell, the last axis is(lower_offset, upper_offset).
The interval becomes [prediction + lower_offset, prediction + upper_offset]. Note that lower_offset is typically negative
and upper_offset positive for non-degenerate intervals.
Returns
Interval, shape (n_series, n_samples, horizon, 2) Last axis is(lower, upper).
Raises
ValueError Ifscore_threshold is not 3-D or 4-D with trailing axis of size 2.
SignedResidual.kind
SignedResidual.score
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) truth : Forecast, shape (n_series, n_samples, horizon)Returns
scores : NDArray, shape (n_series, n_samples, horizon) Signed residuals (truth - prediction). Positive when truth exceeds prediction, negative when truth is below.QuantileScore
Bases: ScoreFunction
Nonconformity score for Conformalized Quantile Regression (CQR).
Unlike :class:AbsoluteResidual, the prediction input is a pair of
quantile forecasts (q_lo, q_hi) rather than a point forecast. The
score measures how far truth falls outside the predicted quantile
interval:
.. math::
invert widens the predicted interval symmetrically by
the score threshold.
QuantileScore.CONSUMES_QUANTILES
QuantileScore.fit
fit before the first call to :meth:score on the
calibration data, so implementations can assume that prediction and
truth are the full calibration arrays.
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon) truth : Forecast, shape (n_series, n_samples, horizon)QuantileScore.from_kind
kind tag names.
Parameters
value : dict A dumped score, carrying akind key.
Returns
ScoreFunctionRaises
ValueError Ifkind is missing or names no registered score. The module
defining a custom score must be imported before loading it.
QuantileScore.invert
score_threshold.
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon, 2) Quantile forecasts. The last axis is(q_lo, q_hi).
score_threshold : NDArray
Either scalar, shape (n_series,), or shape
(n_series, horizon). Broadcast against prediction along
its sample and horizon axes.
Returns
Interval, shape (n_series, n_samples, horizon, 2) Last axis is(lower, upper) with
lower = q_lo - threshold and upper = q_hi + threshold.
Raises
ValueError Ifprediction is not 4-D with a trailing axis of size 2.
QuantileScore.kind
QuantileScore.score
Parameters
prediction : Forecast, shape (n_series, n_samples, horizon, 2) Quantile forecasts. The last axis is(q_lo, q_hi).
truth : Forecast, shape (n_series, n_samples, horizon)
Returns
scores : NDArray, shape (n_series, n_samples, horizon)Raises
ValueError Ifprediction is not 4-D with a trailing axis of size 2, or
if truth does not match prediction.shape[:-1].
ScoreField
None for the method’s default.
Accepts a :class:~conformalforecast.base.ScoreFunction instance or its dump.
SerializeAsAny makes a subclass dump its own fields (and its own kind),
and the before-validator rebuilds a dump as the class its kind names, so a
configured score — custom ones included, once their module is imported —
survives model_validate(model_dump()).
The schema here lists every built-in kind; ConformalMethod narrows it to the
kinds each method accepts.
