WeightFunction
Bases: ArrayModel, ABC
Supplies per-cell weights for the weighted conformal quantile.
Calibration and test weights are separate methods because they are computed
differently: calibration weights must be out-of-fold (a point’s weight may
not come from a model trained on it), while test weights come from a model
fitted on all available data.
WeightFunction.fit_source
Parameters
X : Exog or None, shape (n_series, n_windows, horizon, n_features) shape : tuple of int The(n_series, n_windows, horizon) shape of the calibration
scores the weights must align with.
valid : NDArray of bool or None, shape (n_series, n_windows, horizon)
False marks a cell whose calibration window does not exist for that
series — a ragged panel’s left-NaN padding. Features in those cells
are NaN by construction, so a weight function that fits a model on
them must leave them out. None means every cell is a real window.
Raises
ValueError Ifvalid is given and its shape is not shape.
WeightFunction.fit_target
Parameters
X : Exog or None, shape (n_series, n_samples, horizon, n_features)WeightFunction.calibration_weights
Returns
NDArray, shape (n_series, n_windows, horizon)WeightFunction.test_weights
w(x_test) term).
Parameters
X : Exog or None, shape (n_series, n_samples, horizon, n_features) When None, one sample is assumed.Returns
NDArray, shape (n_series, n_samples, horizon)DensityRatioEstimator
Bases: Protocol
Binary probabilistic classifier used to estimate a density ratio.
Structural (not nominal) on purpose: any object exposing fit and
predict_proba satisfies it, so scikit-learn, XGBoost, LightGBM and
CatBoost classifiers all plug in with no wrapper and no subclassing.
DensityRatioEstimator.fit
X (n, n_features) and binary labels y (n,).
DensityRatioEstimator.predict_proba
(n, 2), column 1 = P(y=1|x).
DensityRatio
Bases: WeightFunction
Density-ratio weights estimated by a binary classifier.
Source rows are labelled 0 and target rows 1; the fitted classifier’s odds
p / (1 - p) estimate d_target(x) / d_source(x), the importance
weight for conformal prediction under covariate shift (Tibshirani et al.,
2019).
Calibration weights are computed out-of-fold: a calibration point’s
weight never comes from a model that trained on it. Test weights come from
a final model fitted on all data.
Parameters
estimator : DensityRatioEstimator Any object withfit(X, y) and predict_proba(X) -> (n, 2).
Required — this package ships no default, so it gains no dependency.
A fresh copy is not made; supply a distinct instance per
DensityRatio if the estimator is stateful.
cv : int, default 5
Cross-fitting folds. Values below 2 disable cross-fitting, in which
case calibration weights come from a model fitted on all data (faster,
but the weights are optimistically biased).
clip_quantile : float or None, default 0.99
Upper quantile at which weights are clipped, so one extreme weight
cannot dominate the weighted quantile. None disables clipping.
standardize : bool, default True
Standardize features to zero mean and unit variance before fitting.
seed : int, default 0
Seed for the fold assignment. Never None.
Raises
pydantic.ValidationError Ifcv is negative, or clip_quantile is outside (0, 1] — a
subclass of ValueError.
DensityRatio.fit_target
Parameters
X : Exog, shape (n_series, n_samples, horizon, n_features)Raises
ValueError If source features were not supplied atfit_source; if the
target feature count disagrees with the source; if a source cell
the valid mask marks as a real window is non-finite; or if the
target features contain any non-finite value.
DensityRatio.calibration_weights
Returns
NDArray, shape (n_series, n_windows, horizon) Uniform ones whenfit_target has not been called, so an
unadapted DensityRatio recovers unweighted split conformal.
DensityRatio.test_weights
w(x_test) term).
Parameters
X : Exog or None, shape (n_series, n_samples, horizon, n_features)Returns
NDArray, shape (n_series, n_samples, horizon)UniformWeights
Bases: WeightFunction
Constant unit weights. Recovers unweighted split conformal exactly.
This is the default when no weighting is supplied, so an un-weighted
WeightedSplit behaves identically to SplitConformal.
UniformWeights.calibration_weights
UniformWeights.test_weights
PrecomputedWeights
Bases: WeightFunction
User-supplied calibration weights.
The escape hatch for weights computed outside this package. Test weights
are uniform: with weights fixed in advance there is no model from which to
evaluate w(x_test).
Parameters
weights : NDArray, shape (n_series, n_windows, horizon) Non-negative, finite weights aligned with the calibration scores.Raises
ValueError Ifweights is not 3-D or contains a negative or non-finite entry.

