What is the equivalent to rpart.plot in Python? I want to visualize the results of my random forest

5.5k views Asked by At

In [R], you can visualize the results of your random forest like so (image shamelessly stolen from the internet). What is the equivalent in Python? I can get the results of my sklearn random forest classification using feature_importances_ , but I want to know which direction they send the result. I realize with a deep forest I won't be able to examine every branch, but maybe it can weight the probabilities? Thanks.

1

There are 1 answers

1
Sidon On

Use the parameters of tree.export_graphviz, see this example and image result:

tree.export_graphviz(clf, out_file=out, feature_names=['alcohol', 'income'],class_names=['0','1'], 
                     filled=True, rounded=True, special_characters=True)

graph=pydotplus.graph_from_dot_data(out.getvalue())
Image(graph.create_png())

Image Result

enter image description here

See the jupyter notebook on github and project details.