cv.folds>时,R gbm函数出错0 [英] Error in R gbm function when cv.folds > 0

查看:123
本文介绍了cv.folds>时,R gbm函数出错0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gbm预测二进制响应. 当我设置cv.folds = 0时,一切正常.但是,当cv.folds> 1时,当交叉验证的第一个刺激完成时,出现错误:Error in object$var.levels[[i]] : subscript out of bounds.有人说这可能是因为某些因子变量在训练或测试数据中缺少水平,但是我尝试仅使用数字变量仍然会出现此错误.

I am using gbm to predict binary response. When I set cv.folds=0, everything works well. However when cv.folds > 1, I got error:Error in object$var.levels[[i]] : subscript out of bounds when the first irritation of crossvalidation finished. Someone said this could because some factor variables have missing levels in training or testing data, but I tried only use numeric variables and still get this error.

> gbm.fit <- gbm(model.formula,
+                data=dataall_train,
+                distribution = "adaboost",
+                n.trees=10,
+                shrinkage=0.05,
+                interaction.depth=2,
+                bag.fraction = 0.5,
+                n.minobsinnode = 10,      
+                train.fraction=0.5,
+                cv.folds=3,
+                verbose=T,
+                n.cores=1)
CV: 1 
CV: 2 
CV: 3 
Error in object$var.levels[[i]] : subscript out of bounds

有人对此有见解吗?谢谢!

Anyone have some insights on this? Thanks!

回答我的自我: 问题解决了.这是因为此功能存在错误.输入数据中不能包含模型中的变量以外的其他变量.

Answer my self: Problem solved. This is because a bug in this function. The input data cannot contain variables other than the variables in the model.

推荐答案

我第二个解决方案:R函数 gbm()中的输入数据不能包含不会被包含的变量(列).在模型中使用.

I second this solution: The input data in the R function gbm() cannot include the variables (columns) that will not be used in your model.

这篇关于cv.folds>时,R gbm函数出错0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆