如何调整sklearn中plot_tree图的大小以使其可读?

chi*_*913 8 python tree matplotlib scikit-learn

我正在尝试从with绘制一个plot_tree对象,但我的树图看起来不太好。我的树图看起来被压扁了:sklearnmatplotlib

在此输入图像描述

下面是我的代码:

from sklearn import tree
from sklearn.model_selection import cross_val_score
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt

# create tree object 
model_gini_class = tree.DecisionTreeClassifier(criterion='gini')

# train the model using the training sets and check score
model_gini_class.fit(X_train, y_train)
model_gini_class.score(X_train, y_train)

# predict output
predicted_gini_class = model_gini_class.predict(X_test)

plt.figure()
tree.plot_tree(model_gini_class, filled=True)
plt.title("Decision trees on the Shakespear dataset (Gini)")
plt.show() # the tree looks squished?
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

  • 有人可以告诉我如何调整sklearnplot_tree对象的大小,使其看起来不被压扁吗?

谢谢你,

小智 6

这可能有帮助

plt.figure(figsize=(10,10))
Run Code Online (Sandbox Code Playgroud)