gpt4 book ai didi

r - 重要性排名 : error must be an object of class xgb. 助推器

转载 作者:行者123 更新时间:2023-12-05 02:31:52 25 4
gpt4 key购买 nike

我运行了一个 xgboost 回归预测(也尝试用 xgb.Booster.complete 完成它)。尝试获取 xgb.importance 时,我收到错误信息

Error in xgboost::xgb.importance(case_xgbm) : model: must be anobject of class 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)

最佳答案

尝试xgboost::xgb.importance(model=xgbc)这对我有用

关于r - 重要性排名 : error must be an object of class xgb. 助推器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71398162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com