首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >了解R gbm封装中的树结构

了解R gbm封装中的树结构
EN

Stack Overflow用户
提问于 2015-07-08 15:03:05
回答 1查看 4.6K关注 0票数 5

我有一些困难,了解树是如何在R的gbm梯度增强机器包的结构。具体来说,查看pretty.gbm.tree 的输出(这些特性在中执行索引)指向。

我在一个数据集上训练了一个GBM,这里是我的一棵树的顶部--调用pretty.gbm.tree的结果

代码语言:javascript
复制
   SplitVar SplitCodePred LeftNode RightNode MissingNode ErrorReduction Weight   Prediction
0         9  6.250000e+01        1         2          21      0.6634681   5981  0.005000061
1        -1  1.895699e-12       -1        -1          -1      0.0000000   3013  0.018956988
2        31  4.462500e+02        3         4          20      1.0083722   2968 -0.009168477
3        -1  1.388483e-22       -1        -1          -1      0.0000000   1430  0.013884830
4        38  5.500000e+00        5        18          19      1.5748155   1538 -0.030602956
5        24  7.530000e+03        6        13          17      2.8329899    361 -0.078738904
6        41  2.750000e+01        7        11          12      2.2499063    334 -0.064752766
7        28 -3.155000e+02        8         9          10      1.5516610     57 -0.243675567
8        -1 -3.379312e-11       -1        -1          -1      0.0000000     45 -0.337931219
9        -1  1.922333e-10       -1        -1          -1      0.0000000     12  0.109783128
代码语言:javascript
复制
It looks to me here that the indices are 0 based, from looking at how `LeftNode, RightNode`, and `MissingNode` point to different rows.  When testing this out by using data samples and following it down the tree to their prediction, I get the correct answer when I consider `SplitVar` to be using **1 based indexing**.

However, 1 of the many trees I build has a _zero_ in the `SplitVar` column!  Here is this tree:

```javascript

SplitVar SplitCodePred LeftNode RightNode MissingNode ErrorReduction权重预测

0 4 1.462500e+02 1 2 21 0.41887 5981 0.0021651262

1 -1 4.117688e-22 -1 -1 -1 0.00000 512 0.0411768781

2 4 1.472500e+02 3 4 20 1.05222 5469 -0.0014870985

3 -1 -2.062798 e-11 -1 -1 -1 0.00000 23 -0.2062797579

4 0 4.750000e+00 5 6 19 0.65424 5446 -0.0006222011

5 -1 3.564879 e-23 -1 -1 -1 0.00000 4897 0.0035648788

6 28 -3.195000e+02 7 11 18 1.39452 549 -0.0379703437

代码语言:javascript
复制

:查看gbm树使用的索引的正确方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-26 22:05:38

使用pretty.gbm.tree时打印的第一列是在脚本pretty.gbm.tree.R中分配的row.names。在脚本中,row.names被赋值为row.names(temp) <- 0:(nrow(temp)-1),其中temp是存储在data.frame表单中的树信息。正确的解释row.names的方法是将其读取为node_id,并为根节点分配0值。

在你的例子中:

Id SplitVar SplitCodePred LeftNode RightNode MissingNode ErrorReduction Weight Prediction 0 9 6.250000e+01 1 2 21 0.6634681 5981 0.005000061

这意味着根节点(由行号0表示)被第9个拆分变量拆分(这里的拆分变量的编号从0开始,因此拆分变量是训练集x中的第10列)。SplitCodePred of 6.25表示所有低于6.25的点数都归给了LeftNode 1,而大于6.25的所有点都被分配给了RightNode 2。该列中缺少值的所有点都分配给了MissingNode 21。由于这种分裂,ErrorReduction0.6634,根节点中有5981 (Weight)。Prediction of 0.005表示在分割点之前分配给此节点上所有值的值。对于-1SplitVarLeftNodeRightNodeMissingNode中表示的终端节点(或叶子),Prediction表示属于该叶节点的所有点的预测值(调整时间)乘以shrinkage

要理解树的结构,首先要注意的是树的分裂是以一种深度的方式发生的。因此,当根节点(节点id为0)被分割为其左节点和右节点时,将处理左侧节点,直到在返回和标记右节点之前不可能进一步拆分。在示例中的两棵树中,RightNode的值为2,这是因为在这两种情况下,LeftNode最终都是叶节点。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31296541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档