简体   繁体   中英

Hide name of criterion in plot_tree() function

I need the graph from plot_tree() function to be displayed without a criterion value in each node of tree. That is, I want to get a picture like that:

在此处输入图像描述

withoun using Paint:) How can I do it?

You can do this by using the impurity=False argument. Here is a reproducible piece of code for you -

from sklearn.datasets import load_iris
from sklearn import tree
import matplotlib.pyplot as plt

#load data
iris = load_iris()

#model training
clf = tree.DecisionTreeClassifier(random_state=0)
clf.fit(iris.data, iris.target)

#plotting
fig = plt.figure(figsize=(10,10))
tree.plot_tree(clf, filled=True, impurity=False)  #<-----------
plt.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM