如何读取graphviz决策树?

2024-05-19 12:25:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用ScikitLearn的export_graphviz函数获得了一个决策树graphviz文件。为了简单起见,我将深度限制为3,因此得到以下输出:

digraph Tree {
node [shape=box] ;
0 [label="userAcceleration-magnitude-mean <= 0.973\ngini = 0.875\nsamples = 3878\nvalue = [471, 467, 485, 484, 486, 486, 513, 486]\nclass = Walking"] ;
1 [label="userAcceleration-x-IQR <= 0.073\ngini = 0.834\nsamples = 2881\nvalue = [471, 443, 476, 484, 9, 486, 512, 0]\nclass = Walking"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="rotationRate-z-IQR <= 0.396\ngini = 0.606\nsamples = 1020\nvalue = [466, 80, 43, 2, 0, 429, 0, 0]\nclass = Push-ups"] ;
1 -> 2 ;
3 [label="gini = 0.355\nsamples = 515\nvalue = [5, 74, 28, 2, 0, 406, 0, 0]\nclass = Resting"] ;
2 -> 3 ;
4 [label="gini = 0.164\nsamples = 505\nvalue = [461, 6, 15, 0, 0, 23, 0, 0]\nclass = Push-ups"] ;
2 -> 4 ;
5 [label="rotationRate-magnitude-median <= 0.844\ngini = 0.764\nsamples = 1861\nvalue = [5, 363, 433, 482, 9, 57, 512, 0]\nclass = Walking"] ;
1 -> 5 ;
6 [label="gini = 0.596\nsamples = 974\nvalue = [2, 73, 388, 476, 0, 23, 12, 0]\nclass = Lunges"] ;
5 -> 6 ;
7 [label="gini = 0.571\nsamples = 887\nvalue = [3, 290, 45, 6, 9, 34, 500, 0]\nclass = Walking"] ;
5 -> 7 ;
8 [label="userAcceleration-y-max <= 2.702\ngini = 0.533\nsamples = 997\nvalue = [0, 24, 9, 0, 477, 0, 1, 486]\nclass = Running"] ;
0 -> 8 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
9 [label="rotationRate-z-IQR <= 2.4\ngini = 0.236\nsamples = 536\nvalue = [0, 22, 6, 0, 466, 0, 1, 41]\nclass = Jump Rope"] ;
8 -> 9 ;
10 [label="gini = 0.553\nsamples = 53\nvalue = [0, 11, 6, 0, 3, 0, 0, 33]\nclass = Running"] ;
9 -> 10 ;
11 [label="gini = 0.08\nsamples = 483\nvalue = [0, 11, 0, 0, 463, 0, 1, 8]\nclass = Jump Rope"] ;
9 -> 11 ;
12 [label="altitude-median <= 5.0\ngini = 0.068\nsamples = 461\nvalue = [0, 2, 3, 0, 11, 0, 0, 445]\nclass = Running"] ;
8 -> 12 ;
13 [label="gini = 0.0\nsamples = 445\nvalue = [0, 0, 0, 0, 0, 0, 0, 445]\nclass = Running"] ;
12 -> 13 ;
14 [label="gini = 0.477\nsamples = 16\nvalue = [0, 2, 3, 0, 11, 0, 0, 0]\nclass = Jump Rope"] ;
12 -> 14 ;
}

让我们集中讨论前两个节点:

^{pr2}$

我不明白的是:

  1. 如果用户加速度幅值平均值小于或等于0.973,那么这个类是“Walking”,否则我跳到节点1,对吗?还是反过来?在
  2. 如何阅读以“gini=0.596”开头的标签?基尼不是我的决策树的特征,这意味着什么?在
  3. 其他的值,比如nsamples和nvalue呢?它们代表什么?在

Tags: 决策树runninglabelgraphvizropejumpgininsamples
1条回答
网友
1楼 · 发布于 2024-05-19 12:25:52

1:如果用户加速度幅值平均值小于或等于0.973,则按True。(这是继续向下进入树。)

他说:我在谷歌上搜索了一下,发现了“基尼系数:一种用一组数值表示的变异程度的统计指标,特别用于分析收入不平等。”。我认为这已经脱离了经济背景,但我不确定是否是这样。在

第三章: 这里面有一个潜在的结构。samples是应用于该节点的样本量。根节点有3878个样本,左子节点有2881个样本,右子节点有997个样本。由于2881+997=3878,我认为对于2881个样本,user-acceleration-magnitude-mean <= 0.973是正确的。其余997个样本分别为假。在

这些值也有某种潜在的结构。value列表中每个值的总和等于该节点中samples的数量。在

相关问题 更多 >