【问题标题】:Hide name of criterion in plot_tree() function在 plot_tree() 函数中隐藏标准名称
【发布时间】:2022-01-02 07:10:45
【问题描述】:

我需要 plot_tree() 函数中的图形在树的每个节点中显示没有标准值。也就是说,我想得到这样的图片:

不使用 Paint :) 我该怎么做?

我还需要将“value”这个词替换为“proba”这个词,是否只能通过更改代码源?

【问题讨论】:

  • 你尝试过使用 Tkinter 吗?这是一个不错的python模块
  • 只需在plot_tree()方法中使用参数impurity=False即可。详情请查看我的回答。

标签: python plot scikit-learn decision-tree


【解决方案1】:

您可以使用impurity=False 参数来做到这一点。这是一段可重现的代码 -

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()

【讨论】:

  • 非常感谢!我认为这个论点具有其他功能。我还需要将“value”这个词替换为“proba”这个词,是否仅通过更改代码源?
  • 您可以使用proportion=True 将计数更改为比例,但values 标签仍然保持不变。但是,如果这对您有用,您可以隐藏所有标签。检查this documentation page 以获取更多参数
猜你喜欢
  • 2021-10-31
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
  • 1970-01-01
  • 2018-03-23
  • 2010-12-05
  • 1970-01-01
相关资源
最近更新 更多