Assuming your Random Forest model is already installed, you must first import the export_graphviz
function export_graphviz
:
from sklearn.tree import export_graphviz
In your loop, you can do the following to create a dot
file
export_graphviz(tree_in_forest, feature_names=X.columns, filled=True, rounded=True)
The next line generates a png file
os.system('dot -Tpng tree.dot -o tree.png')
source share