Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Plot Python XGBdecision tree on Databricks

I am having an issue to plot Xgboost decision tree on databricks. XGboost is installed for python which makes things bit weird when working in this environment.

import xgboost as xgb
from xgboost import plot_importance

gbm=xgb.XGBClassifier().fit(X_train, y_train)
xgb.plot_tree(gbm)

This gives an error:

failed to execute ['dot', '-Tpng'], make sure the Graphviz executables are on your systems' PATH.

I have graphviz installed as a package on databricks side.

like image 697
uxke Avatar asked Oct 29 '25 06:10

uxke


1 Answers

I ran into a similiar issue with displaying sklearn decision tree while on databricks.

My solution was to update the source code of the plot_tree function to return the figure in additions to the annotations it normally returns.

Here is an extract of a databricks notebook showing a working example. I imagine that xgboost has a similiar issue/design.

https://github.com/Foley-CJ/Tree_Plot/blob/master/Tree_Plot.ipynb

like image 111
CJ_Spaz Avatar answered Oct 31 '25 02:10

CJ_Spaz