增加决策树中节点的大小

increase the size of nodes in 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 传递给 tree.plot_tree 并使用大 figsize 并设置更大的 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)

输出: