2
$\begingroup$

I need to compute some metrics for binary classification. I see that many times some people use the probability:

y_pred_proba = clf.fit(X_train, y_train).predict_proba(X_test)
roc_auc_score(y_test, y_pred_proba[:,1]) # probability of Class 1

and other times:

y_pred = clf.fit(X_train, y_train).predict(X_test)
roc_auc_score(y_test, y_pred) # binary outcome y_pred

if I try both I get completely different results.

Can anyone explain me which one has to be used with metrics score, if predict or predict_proba?

$\endgroup$
4
  • 1
    $\begingroup$ AUROC requires probabilities of the predictions, not classes. Your second approach is wrong. $\endgroup$ – user2974951 Jan 25 at 8:30
  • $\begingroup$ great! many thanks, is this true for all the metrics? f1_score, recall_score etc.? $\endgroup$ – Luigi87 Jan 25 at 8:31
  • 1
    $\begingroup$ No. F1, recall and similar require classes. Obligatory reference, because someone will link it eventually, Why is accuracy not the best measure for assessing classification models?. $\endgroup$ – user2974951 Jan 25 at 8:34
  • $\begingroup$ ok great! if you are willing to answer I will vote up your answer! $\endgroup$ – Luigi87 Jan 25 at 8:35
2
$\begingroup$

AUROC is a semi-proper scoring rules and actually uses the raw probabilities to calculate the best threshold to differentiate the two classes, that is in comparison to a default call to predict, which uses the "non-informative" threshold of 0.5.

Other measures such as accuracy, F1, recall, and others are not proper scoring rules, and they work on classes, so they do not bother with the actual probabilities but require you to classify the observations beforehand.

See the linked thread for some more details about why these are not the best metrics.

$\endgroup$
2
  • $\begingroup$ just one more comment please. If i get it right, roc_auc score must always be preferred to f1_score, recall score, prcision_score, because the latter are based on class, while roc_auc on probs. This is true even if I have an imbalanced dataset in which I want to minimise False Negative (for this I should use recall_score), is this statement right? $\endgroup$ – Luigi87 Jan 25 at 9:34
  • 1
    $\begingroup$ @Luigi87 AUROC is a better alternative than F1, recall, precision, etc., as you said, because it incorporates more information from the probabilities, rather than just discrete classes. If I had to choose then I would rather choose AUROC, however, as the thread mentions, there are even better alternatives, such as Brier score. $\endgroup$ – user2974951 Jan 25 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.