1

我正在尝试使用 R 中的多类因变量调整 xgboost 模型。我正在使用 MLR 来执行此操作,但是我遇到了一个错误,即 xgboost 在其命名空间中没有预测 - 我假设 MLR 想要使用。我在网上查了一下,发现其他人也遇到过类似的问题。但是,当我尝试实施它们时,我无法完全理解已提供的答案(例如https://github.com/mlr-org/mlr/issues/935 ),问题仍然存在。我的代码如下:

# Tune parameters
#create tasks
train$result <- as.factor(train$result)  # Needs to be a factor variable for makeClass to work
test$result <- as.factor(test$result)
traintask <- makeClassifTask(data = train,target = "result")
testtask <- makeClassifTask(data = test,target = "result")

lrn <- makeLearner("classif.xgboost",predict.type = "response")

# Set learner value and number of rounds etc.
lrn$par.vals <- list(
 objective = "multi:softprob",  # return class with maximum probability,
 num_class = 3,  # There are three outcome categories
 eval_metric="merror",
 nrounds=100L,
  eta=0.1
)

# Set parameters to be tuned
params <- makeParamSet(
 makeDiscreteParam("booster",values = c("gbtree","gblinear")),
 makeIntegerParam("max_depth",lower = 3L,upper = 10L),
 makeNumericParam("min_child_weight",lower = 1L,upper = 10L),
 makeNumericParam("subsample",lower = 0.5,upper = 1),
 makeNumericParam("colsample_bytree",lower = 0.5,upper = 1)
)

# Set resampling strategy
rdesc <- makeResampleDesc("CV",stratify = T,iters=5L)

# search strategy
ctrl <- makeTuneControlRandom(maxit = 10L)
#parallelStartSocket(cpus = detectCores())  # Enable parallel processing

 mytune <- tuneParams(learner = lrn
                 ,task = traintask
                 ,resampling = rdesc
                 ,measures = acc
                 ,par.set = params
                 ,control = ctrl
                 ,show.info = T)

我得到的具体错误是: Error: 'predict' is not an exported object from 'namespace:xgboost'

我的包版本是:

packageVersion("xgboost")
[1] ‘0.6.4’

packageVersion("mlr")
[1] ‘2.8’

有人知道我应该在这里做什么吗?

提前致谢。

4

0 回答 0