ConformalPredictor

conformal.ConformalPredictor(self, regressor, alpha=0.05)

A class used to represent a (Split) Conformal Predictor.

\[ \hat{C}_{\alpha}(x) = [\hat{u}(x) \pm q_{1 - \alpha}(\mathcal{S})] \]

Parameters

Name Type Description Default
regressor object A regressor object that has a ‘predict’ method. required
alpha float The significance level used in the prediction interval calculation. 0.05

Attributes

Name Type Description
scores ndarray The conformity scores of the calibration data.
quantile float The \((1 - \alpha)\) empirical quantile of the conformity scores.

Methods

Name Description
fit Calibrates the conformal predictor using the provided calibration set.
predict Predicts the output for the given input X and provides a prediction interval.

fit

conformal.ConformalPredictor.fit(X, y)

Calibrates the conformal predictor using the provided calibration set.

Specifically, the fit method learns

\[ q_{1 - \alpha}(S) \]

where \(q_{1 - \alpha}(S)\) is the \((1 - \alpha)\) empirical quantile of the conformity scores

\[ \mathcal{S} = \{|y_i - \hat{u}(x_i)|\} \cup \{ \infty \} \]

Parameters

Name Type Description Default
X ndarray The input data for calibration. required
y ndarray The output data for calibration. required

predict

conformal.ConformalPredictor.predict(X)

Predicts the output for the given input X and provides a prediction interval.

\[ \hat{C}_{\alpha}(x) = [\hat{u}(x) \pm q_{1 - \alpha}(\mathcal{S})] \]

Parameters

Name Type Description Default
X ndarray The input data for which to predict the output. required

Returns

Type Description
tuple A tuple containing the prediction (1D ndarray) and the lower (1D ndarray) and upper bounds (1D ndarray) of the prediction interval.