chemicalchecker.tool.targetmate.nonconformist.icp.IcpRegressor

class IcpRegressor(nc_function, condition=None)[source]

Bases: BaseIcp, RegressorMixin

Inductive conformal regressor.

Parameters

nc_functionBaseScorer

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).

Attributes

cal_xnumpy array of shape [n_cal_examples, n_features]

Inputs of calibration set.

cal_ynumpy array of shape [n_cal_examples]

Outputs of calibration set.

nc_functionBaseScorer

Nonconformity scorer object used to calculate nonconformity scores.

See also

IcpClassifier

References

Examples

>>> import numpy as np
>>> from sklearn.datasets import load_boston
>>> from sklearn.tree import DecisionTreeRegressor
>>> from nonconformist.base import RegressorAdapter
>>> 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):]
>>> model = RegressorAdapter(DecisionTreeRegressor())
>>> nc = RegressorNc(model, 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]])

Methods

calibrate

Calibrate conformal predictor based on underlying nonconformity scorer.

fit

Fit underlying nonconformity scorer.

get_params

Get parameters for this estimator.

get_problem_type

predict

Predict the output values for a set of input patterns.

set_params

Set the parameters of this estimator.

calibrate(x, y, increment=False)

Calibrate conformal predictor based on underlying nonconformity scorer.

Parameters

xnumpy array of shape [n_samples, n_features]

Inputs of examples for calibrating the conformal predictor.

ynumpy array of shape [n_samples, n_features]

Outputs of examples for calibrating the conformal predictor.

incrementboolean

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

xnumpy array of shape [n_samples, n_features]

Inputs of examples for fitting the nonconformity scorer.

ynumpy 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

deepbool, default=True

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

Returns

paramsdict

Parameter names mapped to their values.

predict(x, significance=None)[source]

Predict the output values for a set of input patterns.

Parameters

xnumpy array of shape [n_samples, n_features]

Inputs of patters for which to predict output values.

significancefloat

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

pnumpy 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 Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**paramsdict

Estimator parameters.

Returns

selfestimator instance

Estimator instance.