XGBoost - 预测未在命名空间中导出

时间:2017-04-02 00:56:30

标签: r xgboost mlr

我正在尝试使用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’

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

提前致谢。

0 个答案:

没有答案