Is there any built-in function to get the maximum accuracy for a binary probabilistic classifier in scikit-learn?
E.g. to get the maximum F1-score I do:
# AUCPR
precision, recall, thresholds = sklearn.metrics.precision_recall_curve(y_true, y_score)
auprc = sklearn.metrics.auc(recall, precision)
max_f1 = 0
for r, p, t in zip(recall, precision, thresholds):if p + r == 0: continueif (2*p*r)/(p + r) > max_f1:max_f1 = (2*p*r)/(p + r) max_f1_threshold = t
I could compute the maximum accuracy in a similar fashion:
accuracies = []
thresholds = np.arange(0,1,0.1)
for threshold in thresholds:y_pred = np.greater(y_score, threshold).astype(int)accuracy = sklearn.metrics.accuracy_score(y_true, y_pred)accuracies.append(accuracy)accuracies = np.array(accuracies)
max_accuracy = accuracies.max()
max_accuracy_threshold = thresholds[accuracies.argmax()]
but I wonder whether there is any built-in function.