【发布时间】:2020-03-29 04:13:19
【问题描述】:
我正在尝试用matplotlib 从sklearn 绘制一个plot_tree 对象,但我的树状图看起来不太好。我的树状图看起来被压扁了:
下面是我的代码:
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?
所以我的问题是:
- 有人能告诉我如何调整
sklearnplot_tree 对象的大小,使其看起来不会被压扁吗?
谢谢,
【问题讨论】:
标签: python matplotlib scikit-learn tree