predict_proba()

noun

say it: “prih-DIKT PROH-buh” /prɪˈdɪkt ˈproʊbə/

In scikit-learn, the method that returns a classifier's estimated probability for each possible class, for every example.

What does predict_proba() do?

predict_proba() gives, for each row, the classifier's probability for every class, in the order of classes_, adding up to 1. predict() picks the class with the highest; reading the probabilities lets you set your own threshold.

from sklearn.linear_model import LogisticRegression
links = [[0], [1], [2], [6], [8], [9]]   # links in each email
model = LogisticRegression().fit(links, [0, 0, 0, 1, 1, 1])
print(model.predict_proba([[3], [7]]).round(2))
# [[0.75 0.25]     3 links: 0.25 chance of spam
#  [0.07 0.93]]    7 links: 0.93 chance of spam

In a sentence

  • “predict_proba() gave the email a 0.93 chance of being spam.”
  • “She used the second column of predict_proba() to flag only emails above 0.9.”

Level: Journeyman · More Python terms at this level

Updated