# How to visualize Ensemble Models ( Random Forest) with 1000 estimators

I am working on classification problem where I need to categorize the user in buy/ non-buy category. I have around 100 + features or predictors to predict the behavior of user.

I tried to implement with Random forest and Gradient Boosting to get better prediction compare to decision tree. I am getting better performance when I evaluate against performance parameters like roc_auc,accuracy, precision and recall when using ensemble techniques.

I also extracted important features that are responsible for my predictions but I am not able to visualize the model fully. Some how random forest works as black box where i am not getting what is the contribution of each tree, which features are been considered in each trees, etc.

Is there any way through which I can find out more information from Random Forest Model?

• You surely don't want to visualize a RF with 100+ feats and a bigger depth... – Aditya Oct 9 '18 at 13:15

You can try SHAP which visually explains the output of (many) machine learning model(s) including LightGBM and XGBoost.

However, please note that it will not give you the entire Ensemble Model (Trees) as picture.
Further note that it doesn't work for RandomForest

• Seems like SHAP can be of use to derive the meaning of each feature in your model. Thanx – CodeMaster GoGo Oct 10 '18 at 9:56

If you are working in python, sklearn allows you to export a decision tree in DOT format.

The documentation can be found here

from sklearn.tree import export_graphviz
export_graphviz(decision_tree, out_file=None, max_depth=None, feature_names=None, class_names=None, label=’all’, filled=False, leaves_parallel=False, impurity=True, node_ids=False, proportion=False, rotate=False, rounded=False, special_characters=False, precision=3)


There is, also, a helpful guide to extract the result in png

• It is easy to visualize decision tree.I used this approach for decision tree but I am interested in visualizing few tress(if not full) generated from random forest. – CodeMaster GoGo Oct 10 '18 at 9:55