regressor.MultiOutputConformalRegressor
regressor.MultiOutputConformalRegressor(model, alpha=0.1, strategy='bonferroni')Conformal regressor for multi-output (multi-target) regression.
Produces prediction intervals for multiple targets simultaneously, with either marginal (per-target) or joint coverage guarantees.
Parameters
model : object-
A fitted multi-output regression model with a
predictmethod that returns shape(n_samples, n_targets). alpha : float = 0.1-
Miscoverage level. The prediction intervals will contain the true values with probability at least
1 - alpha. Must be in(0, 1). strategy : (marginal, bonferroni, max_residual) = 'marginal'-
Coverage strategy: -
'marginal': Each target gets its own interval at level1 - alpha. No joint coverage guarantee. -'bonferroni': Each target usesalpha / n_targets, giving joint coverage at least1 - alphavia Bonferroni correction. Conservative but simple. -'max_residual': Usesmax_j \|y_j - hat{y}_j\| / sigma_jas a single joint nonconformity score. Provides exact joint coverage for rectangular prediction regions.
Attributes
qhat_ : np.ndarray or float-
Calibrated quantile threshold(s). For
'marginal'and'bonferroni', shape(n_targets,). For'max_residual', a scalar. calibration_scores_ : np.ndarray-
Nonconformity scores from calibration data. For
'marginal'/'bonferroni': shape(n_calib, n_targets). For'max_residual': shape(n_calib,). n_calib_ : int-
Number of calibration samples used.
n_targets_ : int-
Number of output targets.
target_scales_ : np.ndarray of shape (n_targets,)-
Per-target MAD (Median Absolute Deviation) used for normalization in the
'max_residual'strategy. For'marginal'and'bonferroni', all ones (no normalization).
Examples
>>> from sklearn.multioutput import MultiOutputRegressor
>>> from sklearn.ensemble import RandomForestRegressor
>>> from conformalpy.regressor import MultiOutputConformalRegressor
>>>
>>> # Train a multi-output model
>>> model = MultiOutputRegressor(RandomForestRegressor())
>>> model.fit(X_train, y_train) # y_train shape: (n_samples, n_targets)
>>>
>>> # Create conformal regressor
>>> cr = MultiOutputConformalRegressor(model=model, alpha=0.1)
>>> cr.calibrate(X_calib, y_calib)
>>>
>>> # Get prediction intervals for all targets
>>> intervals = cr.predict_interval(X_test)
>>> # intervals shape: (n_samples, 2, n_targets)
>>> # intervals[:, 0, :] = lower bounds
>>> # intervals[:, 1, :] = upper boundsNotes
Coverage Guarantees:
- Marginal: Each target individually satisfies
P(Y_j in C_j(X)) >= 1 - alphabut the joint probability may be lower. - Bonferroni: Joint coverage
P(Y in C(X)) >= 1 - alphavia the union bound. Conservative: the actual joint coverage is typically higher than1 - alpha. - Max residual: Exact joint coverage for rectangular prediction regions using
max_j |r_j| / sigma_jas the nonconformity score.
When to use which strategy:
'marginal': When per-target coverage is sufficient, or targets are nearly independent.'bonferroni': When joint coverage is needed and you want a simple, guaranteed approach. Best for smalln_targets.'max_residual': When you want tight joint rectangular regions. Best when targets have similar scales or are correlated.
References
- Lei, J. & Wasserman, L. (2014). “Distribution-free prediction bands for non-parametric regression.” Journal of the Royal Statistical Society: Series B, 76(1), 71-96.
- Messoudi, S., Destercke, S., & Rousseau, S. (2021). “Copula-based conformal prediction for multi-target regression.” Pattern Recognition, 120, 108101.
See Also
ConformalRegressor : Single-output conformal regressor. CQR : Conformalized Quantile Regression (single-output).
Methods
| Name | Description |
|---|---|
| average_interval_width | Compute average interval width for each target. |
| calibrate | Calibrate the conformal regressor on held-out data. |
| fit | Alias for calibrate() for sklearn API compatibility. |
| get_qhat | Get the calibrated quantile threshold(s). |
| marginal_coverage | Compute per-target marginal coverage. |
| predict | Return point predictions from the base model. |
| predict_interval | Predict intervals for new multi-output samples. |
| score | Compute joint coverage score on test data. |
average_interval_width
regressor.MultiOutputConformalRegressor.average_interval_width(X)Compute average interval width for each target.
Parameters
X : array-like of shape (n_samples, n_features)-
Features of samples.
Returns
widths : np.ndarray of shape (n_targets,)-
Average interval width for each target.
calibrate
regressor.MultiOutputConformalRegressor.calibrate(X, y)Calibrate the conformal regressor on held-out data.
Parameters
X : array-like of shape (n_samples, n_features)-
Calibration features.
y : array-like of shape (n_samples, n_targets)-
True target values for calibration. Must be 2D.
Returns
scores : np.ndarray-
Nonconformity scores for each calibration sample. Shape depends on strategy.
Raises
: ValueError-
If
yis not 2D or has fewer than 2 targets.
fit
regressor.MultiOutputConformalRegressor.fit(X, y)Alias for calibrate() for sklearn API compatibility.
Parameters
X : array-like of shape (n_samples, n_features)-
Calibration features.
y : array-like of shape (n_samples, n_targets)-
True target values for calibration.
Returns
self : MultiOutputConformalRegressor-
Returns self for method chaining.
get_qhat
regressor.MultiOutputConformalRegressor.get_qhat()Get the calibrated quantile threshold(s).
Returns
qhat : np.ndarray or float-
For
'marginal'and'bonferroni': array of shape(n_targets,). For'max_residual': scalar.
Raises
: ValueError-
If called before calibration.
marginal_coverage
regressor.MultiOutputConformalRegressor.marginal_coverage(X, y)Compute per-target marginal coverage.
Parameters
X : array-like of shape (n_samples, n_features)-
Test features.
y : array-like of shape (n_samples, n_targets)-
True target values.
Returns
coverages : np.ndarray of shape (n_targets,)-
Coverage for each target individually.
predict
regressor.MultiOutputConformalRegressor.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 : np.ndarray of shape (n_samples, n_targets)-
Point predictions from the base model.
predict_interval
regressor.MultiOutputConformalRegressor.predict_interval(X, *, alpha=None)Predict intervals for new multi-output 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, usesself.alphafrom init. If scalar, returns(n_samples, 2, n_targets). If array-like, returns(n_samples, 2, n_targets, n_alphas).
Returns
intervals : np.ndarray-
If alpha is None or scalar: shape
(n_samples, 2, n_targets)If alpha is array: shape(n_samples, 2, n_targets, n_alphas)Dimension 1:[lower, upper]bounds.
Raises
: ValueError-
If called before calibration.
score
regressor.MultiOutputConformalRegressor.score(X, y)Compute joint coverage score on test data.
For all strategies, this returns the proportion of samples where all targets fall within their respective intervals.
Parameters
X : array-like of shape (n_samples, n_features)-
Test features.
y : array-like of shape (n_samples, n_targets)-
True target values.
Returns
joint_coverage : float-
Proportion of samples where all targets are covered.