regressor.SplitConformalRegressor
regressor.SplitConformalRegressor(
base_estimator=None,
alpha=0.1,
calibration_size=0.2,
random_state=None,
verbose=0,
)Split conformal regressor with automatic data splitting.
A meta-estimator that accepts an unfitted base estimator, automatically splits the data into training and calibration sets, fits the base estimator on the training set, and calibrates using split conformal prediction on the calibration set.
This is a convenience wrapper around ConformalRegressor that handles the complete workflow when you have a single dataset and want to perform split conformal prediction.
Parameters
base_estimator : estimator = None-
Base regressor that implements
fit()andpredict(). Can be a simple estimator or a sklearn Pipeline. Will be cloned before fitting. alpha : float = 0.1-
Miscoverage level. Prediction intervals will contain the true value with probability at least 1 - alpha. Must be in (0, 1).
calibration_size : float = 0.2-
Proportion of data to use for calibration. Must be in (0, 1).
random_state : int = None-
Random seed for data splitting.
verbose : int = 0-
Verbosity level: - 0: Silent (default) - 1: Key events (fit start/end, split sizes) - 2: Statistics (qhat, score distributions, interval widths) - 3+: Debug (detailed information)
Attributes
model_ : estimator-
The fitted base estimator.
conformal_ : ConformalRegressor-
The calibrated conformal regressor wrapper.
qhat_ : float-
Calibrated quantile threshold (interval half-width).
n_train_ : int-
Number of training samples used.
n_calib_ : int-
Number of calibration samples used.
Examples
>>> from sklearn.ensemble import RandomForestRegressor
>>> from conformalpy.regressor import SplitConformalRegressor
>>>
>>> # Basic usage with simple estimator
>>> scr = SplitConformalRegressor(
... base_estimator=RandomForestRegressor(n_estimators=100),
... alpha=0.1,
... calibration_size=0.2,
... )
>>> scr.fit(X, y)
>>> intervals = scr.predict_interval(X_test)
>>> # intervals[:, 0] = lower bounds
>>> # intervals[:, 1] = upper bounds
>>>
>>> # Works with sklearn Pipeline
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> pipe = Pipeline([
... ('scaler', StandardScaler()),
... ('reg', RandomForestRegressor()),
... ])
>>> scr = SplitConformalRegressor(base_estimator=pipe, alpha=0.1)
>>> scr.fit(X, y)See Also
ConformalRegressor : Conformal regressor for pre-fitted models. CQR : Conformalized Quantile Regression with adaptive intervals. JackknifePlusRegressor : Jackknife+ conformal prediction.
Notes
Use SplitConformalRegressor when:
- You have a single dataset and want end-to-end conformal prediction
- You want automatic train/calibration splitting
- You’re building a sklearn Pipeline
Use ConformalRegressor when:
- You have already fitted your model
- You want explicit control over train/calibration splits
- You’re integrating with an existing training workflow
Methods
| Name | Description |
|---|---|
| fit | Fit the split conformal regressor. |
| get_qhat | Get the calibrated quantile threshold. |
| predict | Return point predictions from the base model. |
| predict_interval | Predict intervals for new samples. |
| score | Compute coverage score on test data. |
fit
regressor.SplitConformalRegressor.fit(X, y)Fit the split conformal regressor.
Splits the data, fits the base estimator on the training set, and calibrates on the calibration set.
Parameters
X : array-like of shape (n_samples, n_features)-
Training features.
y : array-like of shape (n_samples,)-
Training target values.
Returns
self : SplitConformalRegressor-
Returns self for method chaining.
get_qhat
regressor.SplitConformalRegressor.get_qhat()Get the calibrated quantile threshold.
Returns
qhat : float-
The calibrated threshold for interval construction.
predict
regressor.SplitConformalRegressor.predict(X)Return point predictions from the base model.
Parameters
X : array-like of shape (n_samples, n_features)-
Features of samples to predict.
Returns
predictions : ndarray of shape (n_samples,)-
Point predictions from the base model.
predict_interval
regressor.SplitConformalRegressor.predict_interval(X, *, alpha=None)Predict intervals for new samples.
Parameters
X : array-like of shape (n_samples, n_features)-
Features of samples to predict.
alpha : float, list of float, or None = None-
Significance level(s) for prediction. If None, uses self.alpha. If scalar, returns (n_samples, 2). If array-like, returns (n_samples, 2, n_alphas).
Returns
intervals : ndarray-
If alpha is None or scalar: shape (n_samples, 2). If alpha is array: shape (n_samples, 2, n_alphas). Column 0 is lower bound, column 1 is upper bound.
score
regressor.SplitConformalRegressor.score(X, y)Compute coverage score on test data.
Parameters
X : array-like of shape (n_samples, n_features)-
Test features.
y : array-like of shape (n_samples,)-
True target values.
Returns
coverage : float-
Proportion of samples where true value falls within the prediction interval.