nonconformist.icp.IcpRegressor

class nonconformist.icp.IcpRegressor(nc_function, condition=None)

Inductive conformal regressor.

Parameters:

nc_function : BaseScorer

Nonconformity scorer object used to calculate nonconformity of calibration examples and test patterns. Should implement fit(x, y), calc_nc(x, y) and predict(x, nc_scores, significance).

See also

IcpClassifier

References

[R78]Papadopoulos, H., Proedrou, K., Vovk, V., & Gammerman, A. (2002). Inductive confidence machines for regression. In Machine Learning: ECML 2002 (pp. 345-356). Springer Berlin Heidelberg.
[R88]Papadopoulos, H., & Haralambous, H. (2011). Reliable prediction intervals with regression neural networks. Neural Networks, 24(8), 842-851.

Examples

>>> import numpy as np
>>> from sklearn.datasets import load_boston
>>> from sklearn.tree import DecisionTreeRegressor
>>> from nonconformist.icp import IcpRegressor
>>> from nonconformist.nc import RegressorNc, AbsErrorErrFunc
>>> boston = load_boston()
>>> idx = np.random.permutation(boston.target.size)
>>> train = idx[:int(idx.size / 3)]
>>> cal = idx[int(idx.size / 3):int(2 * idx.size / 3)]
>>> test = idx[int(2 * idx.size / 3):]
>>> nc = RegressorNc(DecisionTreeRegressor, AbsErrorErrFunc())
>>> icp = IcpRegressor(nc)
>>> icp.fit(boston.data[train, :], boston.target[train])
>>> icp.calibrate(boston.data[cal, :], boston.target[cal])
>>> icp.predict(boston.data[test, :], significance=0.10)
...     
array([[  5. ,  20.6],
        [ 15.5,  31.1],
        ...,
        [ 14.2,  29.8],
        [ 11.6,  27.2]])

Attributes

cal_x (numpy array of shape [n_cal_examples, n_features]) Inputs of calibration set.
cal_y (numpy array of shape [n_cal_examples]) Outputs of calibration set.
nc_function (BaseScorer) Nonconformity scorer object used to calculate nonconformity scores.
__init__(nc_function, condition=None)
calibrate(x, y, increment=False)

Calibrate conformal predictor based on underlying nonconformity scorer.

Parameters:

x : numpy array of shape [n_samples, n_features]

Inputs of examples for calibrating the conformal predictor.

y : numpy array of shape [n_samples, n_features]

Outputs of examples for calibrating the conformal predictor.

increment : boolean

If True, performs an incremental recalibration of the conformal predictor. The supplied x and y are added to the set of previously existing calibration examples, and the conformal predictor is then calibrated on both the old and new calibration examples.

Returns:

None

fit(x, y)

Fit underlying nonconformity scorer.

Parameters:

x : numpy array of shape [n_samples, n_features]

Inputs of examples for fitting the nonconformity scorer.

y : numpy array of shape [n_samples]

Outputs of examples for fitting the nonconformity scorer.

Returns:

None

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

predict(x, significance=None)

Predict the output values for a set of input patterns.

Parameters:

x : numpy array of shape [n_samples, n_features]

Inputs of patters for which to predict output values.

significance : float

Significance level (maximum allowed error rate) of predictions. Should be a float between 0 and 1. If None, then intervals for all significance levels (0.01, 0.02, …, 0.99) are output in a 3d-matrix.

Returns:

p : numpy array of shape [n_samples, 2] or [n_samples, 2, 99}

If significance is None, then p contains the interval (minimum and maximum boundaries) for each test pattern, and each significance level (0.01, 0.02, …, 0.99). If significance is a float between 0 and 1, then p contains the prediction intervals (minimum and maximum boundaries) for the set of test patterns at the chosen significance level.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self