I am using sklearn's RandomForestClassifier to build a binary prediction model. As expected, I am getting an array of predictions, consisting of 0's and 1's. However I was wondering if it is possible for me to get a value between 0 and 1 along with the prediction array and set a threshold to tune my model. Many thanks in advance


Referring to http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html, you are using teh predict method to derive the binary response. If you call predict_proba, you will get an array of probabilities corresponding to the binary response.

  • $\begingroup$ the method returns 2 values per prediction, (which sum up to 1) as min and max, how can I interpret them ? $\endgroup$
    – emrahozkan
    Mar 23 '17 at 15:23
  • $\begingroup$ The first column is the probability of the positive (or negative, definitely check) outcome, the second column is the probability of the opposite outcome. So you really only need to use one column. $\endgroup$
    – Hobbes
    Mar 23 '17 at 15:36
  • $\begingroup$ The attribute classes_ tells you which column is which. After you fit your model to the data, just use <RFmodel>.classes_ to see columns to which the classes correspond. $\endgroup$
    – darXider
    Mar 23 '17 at 17:15

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.