python - 增加决策树中节点的大小

标签 python matplotlib scikit-learn decision-tree

我正在使用决策树分类器,并想使用 matplotlib 绘制树

我正在使用这个,但节点很小而且不清晰:

from sklearn import tree
import matplotlib.pyplot as plt

plt.figure(figsize=(15,15))
tree.plot_tree(model_dt_smote,filled=True)

最佳答案

您可以将 axe 传递给具有较大 figsizetree.plot_tree 并设置较大的 fontsize,如下所示:

(我无法运行您的代码,然后我发送一个示例)

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

clf = tree.DecisionTreeClassifier(random_state=0)
iris = load_iris()
clf = clf.fit(iris.data, iris.target)

fig, axe = plt.subplots(figsize=(20,10))
tree.plot_tree(clf, ax = axe, fontsize=15)

输出:

enter image description here

关于python - 增加决策树中节点的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69604461/

相关文章:

python - 执行 TFidf 特征联合和返回数字列表的自定义类的正确方法

python - 设置普通 Graphite 烯嵌套查询

Python - 泡沫。如何编辑 SOAP-ENV :Envelope 的命名空间

python - 将 aws 后端连接到 firebase 数据库

python - 如何修复 Pysal 中 LISA 簇 map 的颜色

machine-learning - 在 google colab 上运行但不适用于 kaggle 的简单代码

python - 在Python列表中找到最大尺寸的字符串?

python - 文本周围的边框间隙

python - seaborn swarmplot 中离散类别的可变间距

python-3.x - eli5解释预测XGBoost模型