chemicalchecker.tool.targetmate.nonconformist.cp.TcpClassifier

class TcpClassifier(nc_function, condition=None, smoothing=True)[source]

Bases: BaseEstimator, ClassifierMixin

Transductive conformal classifier.

Parameters

nc_functionBaseScorer

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

smoothingboolean

Decides whether to use stochastic smoothing of p-values.

Attributes

train_xnumpy array of shape [n_cal_examples, n_features]

Inputs of training set.

train_ynumpy array of shape [n_cal_examples]

Outputs of calibration set.

nc_functionBaseScorer

Nonconformity scorer object used to calculate nonconformity scores.

classesnumpy array of shape [n_classes]
List of class labels, with indices corresponding to output columns

of TcpClassifier.predict()

See also

IcpClassifier

References

in a random world. Springer Science & Business Media.

Examples

>>> import numpy as np
>>> from sklearn.datasets import load_iris
>>> from sklearn.svm import SVC
>>> from nonconformist.base import ClassifierAdapter
>>> from nonconformist.cp import TcpClassifier
>>> from nonconformist.nc import ClassifierNc, MarginErrFunc
>>> iris = load_iris()
>>> idx = np.random.permutation(iris.target.size)
>>> train = idx[:int(idx.size / 2)]
>>> test = idx[int(idx.size / 2):]
>>> model = ClassifierAdapter(SVC(probability=True))
>>> nc = ClassifierNc(model, MarginErrFunc())
>>> tcp = TcpClassifier(nc)
>>> tcp.fit(iris.data[train, :], iris.target[train])
>>> tcp.predict(iris.data[test, :], significance=0.10)
...             
array([[ True, False, False],
        [False,  True, False],
        ...,
        [False,  True, False],
        [False,  True, False]], dtype=bool)

Methods

fit

get_params

Get parameters for this estimator.

get_problem_type

predict

Predict the output values for a set of input patterns.

predict_conf

Predict the output values for a set of input patterns, using the confidence-and-credibility output scheme.

set_params

Set the parameters of this estimator.

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 or None

Significance level (maximum allowed error rate) of predictions. Should be a float between 0 and 1. If None, then the p-values are output rather than the predictions.

Returns

pnumpy array of shape [n_samples, n_classes]

If significance is None, then p contains the p-values for each sample-class pair; if significance is a float between 0 and 1, then p is a boolean array denoting which labels are included in the prediction sets.

predict_conf(x)[source]

Predict the output values for a set of input patterns, using the confidence-and-credibility output scheme.

Parameters

xnumpy array of shape [n_samples, n_features]

Inputs of patters for which to predict output values.

Returns

pnumpy array of shape [n_samples, 3]

p contains three columns: the first column contains the most likely class for each test pattern; the second column contains the confidence in the predicted class label, and the third column contains the credibility of the prediction.

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.