如何使用 Matplotlib 渲染决策树的完整图像
我正在研究一个程序来创建决策树。下面的以下方法应保存树的图像:
def save_image(clf_, filename, feat_names, class_names, show=True):
"""Plot the tree and save to file."""
plt.figure(dpi=200)
tree.plot_tree(
clf_, filled=True,
feature_names=feat_names,
class_names=class_names
)
plt.savefig(f'{filename}.png')
if show:
plt.show()
预期:
完整树的输出图像
实际:
输出的图像不是预期的。我该如何解决这个问题?
I am working on a program to create a decision tree. The following method below should save an image of the tree:
def save_image(clf_, filename, feat_names, class_names, show=True):
"""Plot the tree and save to file."""
plt.figure(dpi=200)
tree.plot_tree(
clf_, filled=True,
feature_names=feat_names,
class_names=class_names
)
plt.savefig(f'{filename}.png')
if show:
plt.show()
Expected:
Output image of full tree
Actual:
The image outputted is not what is expected. How can I trouble-shoot this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论