1

I'm trying to use the plot_tree as in this tutorial

I'm using the iris dataset to train the model, this is the code I have:

from numpy import loadtxt
from xgboost import XGBClassifier
from xgboost import plot_tree
import matplotlib.pyplot as plt
import shap



X,y = shap.datasets.iris()
y = pd.Series([v if v==1 else 0 for v in y]) 

model = XGBClassifier()
model.fit(X, y)
# plot single tree
plot_tree(model)
plt.show()

From there, I'm getting this error:

ValueError: Unable to parse node: 0:[petal

I don't know where to look for that since the model does the training and prediction without issues.

I'm using version '0.20.3' of sklearn

enter image description here

2 Answers 2

2

I had the same issue and it wasn't related to the graphviz installation. In my case the problem was that some of my column names of the pandas dataFrame had white space. See also discussion on github.

When I added

df.rename(columns = lambda x: x.replace(' ', '_'), inplace=True)

to my preprocessing it solved the issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, was the same thing for me. Pretty werid
0

Make sure you have graphviz installed. Because the plot_tree of XGboost internally uses graphviz for plotting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.