We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 053723c commit 80b0bfeCopy full SHA for 80b0bfe
sklearn/metrics/tests/test_metrics.py
@@ -303,16 +303,13 @@ def _auc(y_true, y_score):
303
n_samples = y_true.shape[0]
304
ind = np.arange(n_samples)
305
pos_label = np.unique(y_true)[1]
306
- pos = ind[y_true == pos_label]
307
- neg = ind[y_true != pos_label]
308
309
# Count the number of times positive samples are correctly ranked above
310
# negative samples.
311
- n_correct = 0
312
- for i in pos:
313
- for j in neg:
314
- if y_score[i] > y_score[j]:
315
- n_correct += 1
+ pos = y_score[y_true == pos_label]
+ neg = y_score[y_true != pos_label]
+ diff_matrix = pos.reshape(1, -1) - neg.reshape(-1, 1)
+ n_correct = np.sum(diff_matrix > 0)
316
317
return n_correct / float(len(pos) * len(neg))
318
0 commit comments