从 R 中的 GBM 中提取模型

Extracting Model from GBM in R

有人熟悉如何弄清楚 R 中的 gbm 模型内部发生了什么吗?

假设我们想了解如何预测虹膜中的 Petal.Length。为了简单起见,我 运行:

tg=gbm(Petal.Length~.,data=iris)

这有效,当你 运行:

summary(tg)

然后你得到:

Hit <Return> to see next plot: 
                      var rel.inf
Petal.Width   Petal.Width   67.39
Species           Species   32.61
Sepal.Length Sepal.Length    0.00
Sepal.Width   Sepal.Width    0.00

这在直觉上是有道理的。当你 运行 pretty.gbm.tree(tg) 你得到:

  SplitVar SplitCodePred LeftNode RightNode MissingNode ErrorReduction Weight    Prediction
0        2  0.8000000000        1         2           3       184.6764     75  0.0001366667
1       -1 -0.0022989091       -1        -1          -1         0.0000     22 -0.0022989091
2       -1  0.0011476604       -1        -1          -1         0.0000     53  0.0011476604
3       -1  0.0001366667       -1        -1          -1         0.0000     75  0.0001366667

很明显 gbm 认为您按变量 #2 拆分并得到三个独立的回归。我假设 SplitVar==2Petal.Width,因为您在 str(iris) 中看到的顺序是有道理的。

但是缺少什么数据? iris 没有缺失数据。然后我们如何查看创建的三个节点中的每一个节点中发生了什么?

假设我想用 C++ 编写代码用于生产,除了知道您应该根据 Petal.Width >.8.

谢谢,

乔什

参见包mlmeta中的函数gbm2sas,它使用元编程将R对象转换为SAS格式。

SAS 格式类似于 C++,因此既易于阅读又易于破解 C++。