avicohen avicohen - 7 months ago 41
Python Question

How to predict more than one class with random forest in python?

How can I predict more than one class with random forest in python?

I am familiar with the get probability, but how can I know to which class each probability belongs?

Answer

According to the documentation predict returns an array of predicted classes you can use to get the most likely class for each sample.

If you want to use predict_proba to get the probability for all classes, you need to look at the classes_ attribute. This lists the classes in the same order that predict_proba returned its probabilities.