recall_point = 0.95
// Sort label-score tuples by the score in descending order.
sorted_scores = zip(labels, scores)
sorted_scores.sort(key=operator.itemgetter(1), reverse=False)
// Compute error rate
n_match = sum(1 for x in sorted_scores if x[0] == 1)
After Change
// (np.argmax returns the first occurrence of a "1" in a bool array).
threshold_index = np.argmax(np.cumsum(labels) >= recall_point * np.sum(labels))
FP = np.sum(labels[:threshold_index] == 0) // Below threshold (i.e., labelled positive), but should be negative
TN = np.sum(labels[threshold_index:] == 0) // Above threshold (i.e., labelled negative), and should be negative
return float(FP) / float(FP + TN)
"""import operator