diff --git a/sklearn/metrics/ranking.py b/sklearn/metrics/ranking.py index 31c8b6c73ce7d..e719f7eab8583 100644 --- a/sklearn/metrics/ranking.py +++ b/sklearn/metrics/ranking.py @@ -547,12 +547,13 @@ def roc_curve(y_true, y_score, pos_label=None, sample_weight=None, tps = tps[optimal_idxs] thresholds = thresholds[optimal_idxs] - if tps.size == 0 or fps[0] != 0: - # Add an extra threshold position if necessary - tps = np.r_[0, tps] - fps = np.r_[0, fps] - thresholds = np.r_[thresholds[0] + 1, thresholds] - + if tps.size == 0 or fps[0] != 0 or tps[0] != 0: + # Add an extra threshold to ensure that ROC curve always starts at (0,0) + # point + tps = np.r_[0, tps] + fps = np.r_[0, fps] + thresholds = np.r_[thresholds[0] + 1, thresholds] + if fps[-1] <= 0: warnings.warn("No negative samples in y_true, " "false positive value should be meaningless",