8.19.1.15. sklearn.metrics.roc_curve

sklearn.metrics.roc_curve(y_true, y_score, pos_label=None)

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 in range {0, 1} or {-1, 1}. If labels are not binary, pos_label should be explictly given.

y_score : array, shape = [n_samples]

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

pos_label : int

Label considered as positive and others are considered negative.

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

Notes

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, pos_label=2)
>>> fpr
array([ 0. ,  0.5,  0.5,  1. ])
Previous
Next