Home > Software engineering >  sklearn.tree.plot_tree show returns chunk of text instead of visualised tree
sklearn.tree.plot_tree show returns chunk of text instead of visualised tree

Time:10-28

I'm trying to show a tree visualisation using plot_tree, but it shows a chunk of text instead:

from sklearn.tree import plot_tree
plot_tree(t)

(where t is an instance of DecisionTreeClassifier) This is the output:

[Text(464.99999999999994, 831.6, 'X[3] <= 0.8\nentropy = 1.581\nsamples = 120\nvalue = [39, 37, 44]'),
 Text(393.46153846153845, 646.8, 'entropy = 0.0\nsamples = 39\nvalue = [39, 0, 0]'),

and so on and so forth. How do I make it show the visual tree instead? I'm using Jupyter 6.4.1 and I already imported matplotlib earlier in the code. Thanks!

CodePudding user response:

In my case, it works with a simple "show":

plot_tree(t)
plt.show()
  • Related