我正在尝试在(决策树)中可视化图表。我使用 sklearn 库来创建点文件。我使用 sublime text 3.3.2 作为文本编辑器。
python 版本:3.9.1。
我在命令+shift+P之后从安装包安装了Graphiz在 mac 10.15.5 MacOS Catalina 上。
我的代码:
digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="age <= 24.5\ngini = 0.775\nsamples = 32\nvalue = [8, 10, 5, 5, 4]\nclass = Classical", fillcolor="#f4fdee"] ;
1 [label="gender <= 0.5\ngini = 0.5\nsamples = 10\nvalue = [0, 0, 5, 5, 0]\nclass = Dance", fillcolor="#ffffff"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="gini = 0.0\nsamples = 5\nvalue = [0, 0, 0, 5, 0]\nclass = HipHop", fillcolor="#3c39e5"] ;
1 -> 2 ;
3 [label="gini = 0.0\nsamples = 5\nvalue = [0, 0, 5, 0, 0]\nclass = Dance", fillcolor="#39e5c5"] ;
1 -> 3 ;
4 [label="gender <= 0.5\ngini = 0.628\nsamples = 22\nvalue = [8, 10, 0, 0, 4]\nclass = Classical", fillcolor="#ecfbe3"] ;
0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
5 [label="age <= 32.5\ngini = 0.463\nsamples = 11\nvalue = [0, 7, 0, 0, 4]\nclass = Classical", fillcolor="#c6f4aa"] ;
4 -> 5 ;
6 [label="gini = 0.0\nsamples = 4\nvalue = [0, 0, 0, 0, 4]\nclass = Jazz", fillcolor="#e539c0"] ;
5 -> 6 ;
7 [label="gini = 0.0\nsamples = 7\nvalue = [0, 7, 0, 0, 0]\nclass = Classical", fillcolor="#7be539"] ;
5 -> 7 ;
8 [label="age <= 38.5\ngini = 0.397\nsamples = 11\nvalue = [8, 3, 0, 0, 0]\nclass = Accoustic", fillcolor="#efb083"] ;
4 -> 8 ;
9 [label="gini = 0.0\nsamples = 8\nvalue = [8, 0, 0, 0, 0]\nclass = Accoustic", fillcolor="#e58139"] ;
8 -> 9 ;
10 [label="gini = 0.0\nsamples = 3\nvalue = [0, 3, 0, 0, 0]\nclass = Classical", fillcolor="#7be539"] ;
8 -> 10 ;
}
问题
我可以在 Tools 的 Sublime 文本上看到 Graphvizer 插件,但我在我的目录 /usr/local/ 中找不到 graphviz 版本,所以我不确定它已正确安装。
command+shift+G 之后来自 sublime text 的错误消息没有给出任何输出结果,似乎命令甚至没有运行。
我的尝试
我还了解到我也可以使用 xdot 进行可视化,我使用 pip install
下载了该文件。
我的目标是使用我使用 pip 安装的 graphviz 可视化 graph.dot。我使用 jupyter 仪表板创建了 graph.dot
我在 Pycharm 上使用了终端以获得更高的精度。
有人可以帮我弄清楚吗?非常感谢大家!
答案 0 :(得分:0)
使用命令将您的点文件(例如 graph.dot)转换为图像格式(例如 PNG)
dot graph.dot -T png -o graph.png
安装 dot
后。
dot
可执行文件应通过执行 brew install graphviz
与 GraphViz 包一起安装。
然后您可以使用图像查看器打开 PNG。