8.17.1.2. sklearn.metrics.roc_curve

sklearn.metrics.roc_curve(y_true, y_score)

compute Receiver operating characteristic (ROC)

Note: this implementation is restricted to the binary classification task.

Parameters :

y_true : array, shape = [n_samples]

true binary labels

y_score : array, shape = [n_samples]

target scores, can either be probability estimates of the positive class, confidence values, or binary decisions.

Returns :

fpr : array, shape = [>2]

False Positive Rates

tpr : array, shape = [>2]

True Positive Rates

thresholds : array, shape = [>2]

Thresholds on y_score used to compute fpr and tpr.

Note: Since the thresholds are sorted from low to high values, they are reversed upon returning them to ensure they correspond to both fpr and tpr, which are sorted in reversed order during their calculation.

References

http://en.wikipedia.org/wiki/Receiver_operating_characteristic

Examples

>>> import numpy as np
>>> from sklearn import metrics
>>> y = np.array([1, 1, 2, 2])
>>> scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> fpr, tpr, thresholds = metrics.roc_curve(y, scores)
>>> fpr
array([ 0. ,  0.5,  0.5,  1. ])
Previous
Next