在anaconda中运行时如何查看决策树?

数据挖掘 Python 决策树 朱庇特 图片 蟒蛇
2022-02-22 18:19:38

在 Jupyter 中显示 DT 的操作如下:

# Display in jupyter notebook
from IPython.display import Image
Image(filename = 'tree.png')

如何在 anaconda 中看到 DT?

2个回答

下面是我可视化决策树的代码。希望能帮助到你。

在此处输入图像描述

有一种更简单的方法,但有时它首先不起作用,你应该像这样调用你的方法

tree_clf=tree.DecisionTree()

然后你可以为它选择一个名字和路径,让其他人保持和我一样,它看起来像:

from sklearn.tree import export_graphviz
export_graphviz(
tree_clf,
out_file=image_path("iris_tree.dot"),
feature_names=iris.feature_names[2:],
class_names=iris.target_names,
rounded=True,
filled=True
)

希望对你有帮助