问题标签 [gbm]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3496 浏览

r - Error with new data with same number of predictors but different number of rows when using predict()

I am trying to run the prediction function I got after training my model and after cross validation. I am predicting the variable "classe."

The test data has the same name number of predictors as the training data, except it has fewer rows (20 observations). All of the predictors in the test data are numeric (just like training data). But it seems like it's causing problems no matter what models I used.

Model:

I tried:

I got

then I tried

I got

My test data looks like this, the only difference is the last variable indicates a "problem id", whereas in the training set the last variable indicates "classe":

Any help is appreciated!!

0 投票
2 回答
1940 浏览

r - Y 轴在 logit 刻度上并以 gbm.plot 为中心

我目前正在探索 dismo 包中的 gbm 函数,以创建用于物种分布建模的增强回归树。我一直在使用 dismo vignettes 以及 Elith 等人发表在《动物生态学杂志》上的 2008 年论文“增强回归树的工作指南”。在 Elith 等人的第 808:809 页上。文章中,作者解释了部分依赖图,并在第 809 页底部给出了示例(图 6)。根据 dismo 小插图“用于生态建模的 Boosted Regression Trees”,gbm.plot “绘制响应对一个或多个预测变量的部分依赖性”。

Gbm.plot 创建的图看起来几乎与 Elith 等人中的示例完全相同。但是,有一些参数我无法弄清楚如何设置以实现与论文中完全相同的图。

  1. 论文中的 y 轴在 logit 尺度上并且居中以在数据分布上具有零均值。gbm.plot 中的 y 轴表示拟合函数。

  2. 论文中的地毯在图的顶部,gbm.step 地毯在底部。

  3. Gbm.plot 使用变量名称作为 x 轴标签。论文有有意义的轴标签。

这是 Elith 论文中的图与使用 gbm.plot 生成的图的比较

图 6 来自 Elith 等人,2009 年 图 6 来自 Elith 等人,2009 年

来自 gbm.plot 来自 gbm.plot

我的解决方案

在寻找解决方案时,我遇到了这个问题,它给了我查看源代码的想法(对我来说是第一次)。从源头上,我能够很好地了解该功能是如何组合在一起的,但仍有很多我不明白的地方。

  1. 我不确定要更改什么以将 y 轴转换为 logit 比例并将它们居中以使均值为零。

  2. 我能够更改源以将地毯移动到地块的顶部。我找到了 rug 函数的命令并添加了side=3.

  3. 对于变量名,我想我需要列出适当的变量名,将其附加到数据中,并以某种方式将其读入源代码。还在我头上。

我将感谢您的任何意见。我还认为,如果其他生态学家使用 Elith 论文来指导他们,他们可能会遇到同样的问题。

这是我为生成绘图而运行的代码示例

gbm.plot(all.sum.tc4.lr001, rug=TRUE, smooth=TRUE, n.plots=9, common.scale=TRUE, write.title = FALSE, show.contrib=TRUE, plot.layout=c(2,3), cex.lab=1.5)

0 投票
1 回答
756 浏览

r - 如何在 R 中将 GBM 树转换为 rpart 或 ctree?

您是否知道将使用 gbm 包(使用函数提取)获得的树转换pretty.gbm.tree为有关决策树构建(rpartctree)的任何对象的任何方法?

0 投票
1 回答
3024 浏览

r - (R) Plot dendrograms BRT models from gbm.step

(previously posted here, to the wrong sub, with not enough info, which was closed, I edited, the edits seem to have been deleted, & the post consigned to purgatory, so apologies for re-posting, I don't know whether the previous post can/should be resurrected)

In R, I've run some Boosted Regression Trees, aka Generalized Boosting Models, using dismo which uses gbm. Reproducible example to get people to where I am currently:

(From here). This leaves you with gbm model object "angaus.tc5.lr01". I'd like to generate dendrograms of the splits (folds?), i.e. plot the trees, as per De'ath 2007 (see pic, left pane). BUT: De'ath's plot is of a single regression tree, not a boosted regression tree which is the average of potentially thousands of trees each run with a different set of data randomly drawn from the dataset.

User ckluss kindly suggested rpart, however that needs the model to be generated by rpart so doesn't work for BRTs/GBMs produced by gbm.step. The same is true of prp from rpart.plot.

pretty.gbm.tree in gbm extracts a matrix of info for any one tree selected (try pretty.gbm.tree(angaus.tc5.lr01, i.tree=1) for the first) so I'm wondering if this might be a plausible route to success? E.g. by writing some script which creates an averaged tree matrix using all of the available trees, then converting this into a tree-like object, possibly using some of the methods here.

People have asked varyingly similar questions seemingly with no success elsewhere on the net. BRT models are regularly described as being 'black boxes' so maybe the general opinion is that one shouldn't need/be able/bother to probe into them and display their inner processes.

If anyone knows enough about BRTs / gbm and has any ideas, they'd be gratefully received. Thanks.

De'ath tree diagram

0 投票
1 回答
289 浏览

r - Caret 函数 predict.gb() 中可能存在的错误?

在我看来,我在 R 中的 Caret 包中发现了 method=gbm 的 predict() 函数的性能错误。我很想知道其他人是否同意,或者是否有人对这种行为有解释这个功能的。

1. 生成数据

2.使用method="lm"进行预测

以下代码按预期工作:使用 method=“lm” 两个预测值匹配。在第一种情况 p1 中,“y”包含在 newdata 中,在第二种情况下,p2 中不包含。

p1 应该等于 p2,并且:

3.使用method="gbm"进行预测

此代码未按预期工作:使用方法 =“gbm”,设置相同,两个预测值不匹配。

在这种情况下,p1 不等于 p2:

4. 使用不同设置的 method="gbm" 进行预测

但是,奇怪的是,有一个小的变化——没有明确命名子集操作中的变量——它确实有效:

提前感谢我们的想法。

杰夫

0 投票
1 回答
4222 浏览

r - GBM 和 Caret 包:间隔数无效

虽然我正在定义它target <- factor(train$target, levels = c(0, 1)),但下面给出的代码提供了这个错误:

cut.default(y, unique(quantile(y, probs = seq(0, 1, length = cut))) 中的错误:无效的间隔数另外:警告消息:1:在 train.default(x, y , weights = w, ...) : 无法计算回归的类别概率

这是什么意思以及如何解决这个问题?

0 投票
1 回答
849 浏览

c# - 在 C++ 中部署 GBM 模型 | 让 Predict.gbm 在 R 之外工作

有没有办法将 gbm 模型导出到 C++。具体来说,我如何调用 predict.gbm 函数在 R 之外运行以便对新数据集进行评分。

我已将模型导出为 PMML 文件,但我不确定新数据集将如何根据 PMML 得分。

我是 R 新手,花了很多时间试图解决这个问题,但无济于事,我将不胜感激任何线索

提前致谢

0 投票
0 回答
963 浏览

r - 预测栅格多项式 gbm

目前,似乎无法将多项式预测为光栅砖gbm模型预测为光栅砖。但是请注意,对于相对较小的栅格网格,有一种简单的方法可以解决这个问题 - 这将在下面解释。但是,当您处理大型栅格、许多类(在我的例子中是植被群落)和预测变量时,这里的过程非常缓慢并且并非没有挑战。我希望下面的信息可能对遇到同样挑战的任何人有用。

下面我尝试使用多项 gbm 模型和 20 个预测变量来预测 36 个植被群落的发生概率。我的研究区域是一个具有 213,000,000 像素的 30x30m 栅格网格 - 但是下面的代码与我用来开发/测试该过程的 1221 个单元格的小网格有关。

我将预测变量堆叠到栅格堆栈中,如下所示:

检查 rasStack 中的名称是否与上述模型中的名称相同很重要

在运行 predict.gbm 之前,我调用了最好的迭代模型

我可以通过将网格单元转换为一组空间点(如下所示),为我的测试区域创建一组光栅输出图像,该区域有 1221 个单元。

运行 predict.gbm 模型

我可以通过以下方式将 predtable 中的出现概率值写入一组 36 个新光栅图像:

这给了我想要的输出 - 但是 - 而不是必须预测到数据帧 - 如果可以直接预测到 rasterbrick,该过程将更快,更有效。

如果我跑

输出是代表我要预测的第一个植被群落的栅格网格:

IDRISI 文件格式不支持多波段图像,因此我无法将 index=1:36 添加到混合中以生成多波段光栅砖作为输出。如果我尝试这样做 - 设置 format="GTiff" 或 "HFA"(或任何其他需要 rgdal 的格式),我会收到错误消息:

"Error in rgdal::putRasterData(x@file@transient, v, band = 1, offset = off) : 光栅 IO 失败”

但是,如果我设置格式 =“raster”,我可以获得 rasterbrick 输出,但这不会让我读/写除 idrisi 图像(predict.gbm 模型的第一个输出列)中的数据以外的任何数据


“警告消息:在 .rasterFromRasterFile(grdfile, band = band, objecttype, ...) 中:值文件的大小与单元格的数量不匹配(给定数据类型)”

如果我尝试将上面的光栅砖转换为一组单独的光栅图像

这些图像都没有任何意义。

这也有点令人费解,如果我尝试写为多波段 CDF 图像,我会收到一组不同的 rgdal 错误警告消息:

在这里,我不确定发生了什么?

如果有知识的人可以与 gbm 包的作者合作,使其可以直接预测到光栅砖,而不会遇到上述任何问题,那就太好了。

如果有人想知道我在完整栅格网格上使用的代码,请在下面发表评论,我很乐意提供。

欢呼艾伦

0 投票
0 回答
4022 浏览

r - GBM R 包中的 R 平方计算

想要计算 R 中 gbm(梯度提升机)包创建的模型的 R-Squared。在运行 gbm 函数进行 5 折交叉验证后,将交叉验证的拟合值与结果变量的观察值相关联,并对结果。这是推导交叉验证 R-Squared 以评估模型拟合的有效方法吗?代码如下:

输出

训练_RSq

[1] 0.9762177

CV_RSq

[1] 0.8918581

这些结果对我来说很有意义:训练模型 R-Squared > CV R-Squared。train.fraction=1 也是有意义的,因为保留测试样本是多余的(由于交叉验证)。这种为 gbm 计算 R-Squared 的方法似乎有效吗?

0 投票
1 回答
2104 浏览

r - 无法将库“gbm”附加到 R 项目

我安装了库gbm(RStudio)。当我尝试调用它时,它失败了:

应该提到的是,这个库就在一天前工作得很好。我没有对 RStudio 设置进行任何更改。