重要性排名:错误必须是 xgb.Booster 类的对象
我运行了 xgboost 回归预测(也尝试使用 xgb.Booster.complete 来完成它)。当尝试获取 xgb.importance 时,我收到错误消息
xgboost::xgb.importance(case_xgbm) 中的错误:模型:必须是 xgb.Booster 类的对象
但是,在验证时,R 说它是一个“xgb.Booster”类。 知道发生了什么事吗?
library(xgboost)
library(caret)
somedata <- MASS::Boston
indexes = createDataPartition(somedata$medv, p = .85, list = F) #medv is the y
train = somedata[indexes, ]
test = somedata[-indexes, ]
train_x = data.matrix(train[, -13])
train_y = train[,13]
xgb_train = xgb.DMatrix(data = train_x, label = train_y)
xgbc = xgboost(data = xgb_train, max.depth = 2, nrounds = 50)
class(xgbc)
xgboost::xgb.importance(xgbc)
xgbc2 = xgb.Booster.complete(xgbc, saveraw = TRUE)
class(xgbc2)
xgboost::xgb.importance(xgbc2)
I ran a xgboost regression forecast (also tried to complete it with the xgb.Booster.complete). When trying to get the xgb.importance, I get the error massage
Error in xgboost::xgb.importance(case_xgbm) : model: must be an
object of class xgb.Booster
However, when verifying, R says it is an "xgb.Booster" class.
Any idea what is going on?
library(xgboost)
library(caret)
somedata <- MASS::Boston
indexes = createDataPartition(somedata$medv, p = .85, list = F) #medv is the y
train = somedata[indexes, ]
test = somedata[-indexes, ]
train_x = data.matrix(train[, -13])
train_y = train[,13]
xgb_train = xgb.DMatrix(data = train_x, label = train_y)
xgbc = xgboost(data = xgb_train, max.depth = 2, nrounds = 50)
class(xgbc)
xgboost::xgb.importance(xgbc)
xgbc2 = xgb.Booster.complete(xgbc, saveraw = TRUE)
class(xgbc2)
xgboost::xgb.importance(xgbc2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
xgboost::xgb.importance(model=xgbc)
这对我有用
try
xgboost::xgb.importance(model=xgbc)
this worked for me