conformal.regression

Regression module contains methods for conformal regression.

Conformal regressors predict a range of values (not always a single value) under a given significance level (error rate). Every regressors works in combination with a nonconformity measure and on average predicts the correct value with the given error rate. Lower error rates result in narrower ranges of predicted values.

Structure:

class conformal.regression.PredictionRegr(lo, hi)[source]

Bases: object

Conformal regression prediction object, which is produced by the ConformalRegressor.predict() method.

lo

Lowest value of the predicted range.

Type:float
hi

Highest value of the predicted range.

Type:float

Examples

>>> train, test = next(LOOSampler(Table('housing')))
>>> ccr = CrossRegressor(AbsError(LinearRegressionLearner()), 5, train)
>>> prediction = ccr.predict(test[0], 0.1)
>>> print(prediction.width())
__init__(lo, hi)[source]

Initialize the prediction.

Parameters:
  • lo (float) – Lowest value of the predicted range.
  • hi (float) – Highest value of the predicted range.
range()[source]

Predicted range: lo, hi.

verdict(ref)[source]

Conformal regression prediction is correct when the actual value appears in the predicted range.

Parameters:ref – Reference/actual value
Returns:True if the prediction is correct.
width()[source]

Width of the predicted range: hi - lo.

class conformal.regression.ConformalRegressor(nc_measure)[source]

Bases: orangecontrib.conformal.base.ConformalPredictor

Base class for conformal regression.

__init__(nc_measure)[source]

Verify that the nonconformity measure can be used for regression.

predict(example, eps)[source]

Compute a regression prediction object for a given example and significance level.

Function determines what is the eps-th lowest nonconformity score and computes the range of values that would result in a lower or equal nonconformity. This inverse of the nonconformity score is computed by the nonconformity measure’s cp.nonconformity.RegrNC.predict() function.

Parameters:
  • example (Instance) – Orange row instance.
  • eps (float) – Default significance level (error rate).
Returns:

Regression prediction object.

Return type:

PredictionRegr

__call__(example, eps)[source]

Compute predicted range for a given example and significance level.

Parameters:
  • example (Instance) – Orange row instance.
  • eps (float) – Significance level (error rate).
Returns:

Predicted range as a pair (PredictionRegr.lo, PredictionRegr.hi)

class conformal.regression.TransductiveRegressor(nc_measure)[source]

Bases: conformal.regression.ConformalRegressor

Transductive regression. TODO

class conformal.regression.InductiveRegressor(nc_measure, train=None, calibrate=None)[source]

Bases: conformal.regression.ConformalRegressor

Inductive regression.

alpha

Nonconformity scores of the calibration instances. Computed by the fit() method. Must be sorted in increasing order.

Examples

>>> train, test = next(LOOSampler(Table('housing')))
>>> train, calibrate = next(RandomSampler(train, 2, 1))
>>> icr = InductiveRegressor(AbsError(LinearRegressionLearner()), train, calibrate)
>>> print(icr(test[0], 0.1))
__init__(nc_measure, train=None, calibrate=None)[source]

Initialize inductive regressor with a nonconformity measure, training set and calibration set. If present, fit the conformal regressor to the training set and compute the nonconformity scores of calibration set.

Parameters:
  • nc_measure (RegrNC) – Regression nonconformity measure.
  • train (Optional[Table]) – Table of examples used as a training set.
  • calibrate (Optional[Table]) – Table of examples used as a calibration set.
fit(train, calibrate)[source]

Fit the conformal regressor to the training set, compute and store sorted nonconformity scores (alpha) on the calibration set and store the domain.

Parameters:
  • train (Optional[Table]) – Table of examples used as a training set.
  • calibrate (Optional[Table]) – Table of examples used as a calibration set.
class conformal.regression.CrossRegressor(nc_measure, k, train=None)[source]

Bases: conformal.regression.InductiveRegressor

Cross regression.

Examples

>>> train, test = next(LOOSampler(Table('housing')))
>>> ccr = CrossRegressor(AbsError(LinearRegressionLearner()), 4, train)
>>> print(ccr(test[0], 0.1))
__init__(nc_measure, k, train=None)[source]

Initialize cross regressor with a nonconformity measure, number of folds and training set. If present, fit the conformal regressor to the training set.

Parameters:
  • nc_measure (RegrNC) – Regression nonconformity measure.
  • k (int) – Number of folds.
  • train (Optional[Table]) – Table of examples used as a training set.
fit(train)[source]

Fit the cross regressor to the training set. Split the training set into k folds for use as training and calibration set with an inductive regressor. Concatenate the computed nonconformity scores and store them (InductiveRegressor.alpha).

Parameters:train (Table) – Table of examples used as a training set.
class conformal.regression.LOORegressor(nc_measure, train=None)[source]

Bases: conformal.regression.CrossRegressor

Leave-one-out regressor is a cross conformal regressor with the number of folds equal to the size of the training set.

Examples

>>> train, test = next(LOOSampler(Table('housing')))
>>> ccr = LOORegressor(AbsError(LinearRegressionLearner()), train)
>>> print(ccr(test[0], 0.1))
__init__(nc_measure, train=None)[source]

Initialize cross regressor with a nonconformity measure, number of folds and training set. If present, fit the conformal regressor to the training set.

Parameters:
  • nc_measure (RegrNC) – Regression nonconformity measure.
  • k (int) – Number of folds.
  • train (Optional[Table]) – Table of examples used as a training set.
fit(train)[source]

Fit the cross regressor to the training set. Split the training set into k folds for use as training and calibration set with an inductive regressor. Concatenate the computed nonconformity scores and store them (InductiveRegressor.alpha).

Parameters:train (Table) – Table of examples used as a training set.