regressor.JackknifePlusRegressor
regressor.JackknifePlusRegressor(
base_estimator=None,
alpha=0.1,
cv=None,
random_state=None,
)Jackknife+ / CV+ conformal regressor.
Implements the proper jackknife+ procedure of Barber et al. (2021). Per-fold estimators are retained and used at prediction time to build intervals from {μ̂_{-i}(X_test) ± R_i}.
Parameters
base_estimator : estimator = None-
Base regressor implementing
fit()andpredict(). Cloned for each LOO/CV iteration. alpha : float = 0.1-
Significance level. The jackknife+ theorem (Barber et al. 2021, Theorem 1) guarantees
P(Y ∈ C(X)) ≥ 1 − 2α. Empirical coverage is typically much closer to1 − α. cv : int or None = None-
Cross-validation strategy: -
None: Leave-one-out (true jackknife+;nmodel fits). -int: K-fold CV (CV+ for regression;cvmodel fits). random_state : int = None-
Random seed for K-fold shuffling. Ignored when
cv is None.
Attributes
estimators_ : list of estimators-
Per-fold fitted models. Length is
nfor LOO mode, orcvfor K-fold mode. fold_assignment_ : ndarray of shape (n_samples,)-
Index into
estimators_of the held-out estimator for each training sample. residuals_ : ndarray of shape (n_samples,)-
Absolute held-out residuals
R_i = \|y_i − μ̂_{-i}(x_i)\|. model_ : estimator-
Base estimator refit on the full training data. Used by
predict()for point predictions; not used to build intervals. qhat_ : float-
Backwards-compatible scalar threshold computed from
residuals_using the split-conformal formula⌈(n+1)(1−α)⌉/nquantile (withmethod='higher'). Reported for inspection only; not used bypredict_interval().
Examples
>>> from sklearn.ensemble import RandomForestRegressor
>>> from conformalpy.regressor import JackknifePlusRegressor
>>>
>>> jp = JackknifePlusRegressor(
... base_estimator=RandomForestRegressor(n_estimators=100),
... alpha=0.1,
... cv=10,
... )
>>> jp.fit(X_train, y_train)
>>> intervals = jp.predict_interval(X_test)Notes
Computational complexity: - LOO (cv=None): O(n) model fits during fit(); O(n) calls to base_estimator.predict per test batch. - K-fold: O(K) model fits and predictions.
Methods
| Name | Description |
|---|---|
| fit | Fit the jackknife+ regressor using LOO or K-fold CV. |
| predict | Point predictions from the model refit on the full training set. |
| predict_interval | Predict jackknife+ intervals. |
| score | Empirical coverage on test data. |
fit
regressor.JackknifePlusRegressor.fit(X, y)Fit the jackknife+ regressor using LOO or K-fold CV.
Parameters
X : array-like of shape (n_samples, n_features)-
Training features.
y : array-like of shape (n_samples,)-
Training targets.
Returns
self : JackknifePlusRegressor
predict
regressor.JackknifePlusRegressor.predict(X)Point predictions from the model refit on the full training set.
Parameters
X : array-like of shape (n_samples, n_features)
Returns
predictions : ndarray of shape (n_samples,)
predict_interval
regressor.JackknifePlusRegressor.predict_interval(X, alpha=None)Predict jackknife+ intervals.
For each test point x, the interval is
\[ \left[ q^{-}_{\alpha,n}\!\left(\{\hat{\mu}_{-i}(x) - R_i\}\right),\ q^{+}_{\alpha,n}\!\left(\{\hat{\mu}_{-i}(x) + R_i\}\right) \right] \]
where q^{-} is the ⌊α(n+1)⌋-th smallest value and q^{+} is the ⌈(1−α)(n+1)⌉-th smallest value.
Parameters
X : array-like of shape (n_samples, n_features)-
Test features.
alpha : float = None-
Significance level. If
None, usesself.alpha.
Returns
intervals : ndarray of shape (n_samples, 2)-
[lower, upper]per test sample.
score
regressor.JackknifePlusRegressor.score(X, y)Empirical coverage on test data.
Parameters
X : array-like of shape (n_samples, n_features)y : array-like of shape (n_samples,)
Returns
: float-
Proportion of test targets within the predicted intervals.