R xgboost用early.stop.round预测

时间:2016-04-27 12:28:44

标签: r xgboost

我有以下代码。让我们假设优化在600轮之后停止,最佳回合是450.哪个模型将用于预测 - 第450轮之后或600之后?

watchlist <- list(val=dval,train=dtrain)

param <- list(  objective           = "binary:logistic", 
                booster             = "gbtree",
                eval_metric         = "auc",
                eta                 = 0.02,
                max_depth           = 7,
                subsample           = 0.6,
                colsample_bytree    = 0.7
)

clf <- xgb.train(   params              = param, 
                    data                = dtrain, 
                    nrounds             = 2000, 
                    verbose             = 0,
                    early.stop.round    = 150,
                    watchlist           = watchlist,
                    maximize            = TRUE
)

preds <- predict(clf, test)

1 个答案:

答案 0 :(得分:4)

经过一番研究后,我找到了答案。预测将在第600轮后使用模型。如果想要使用具有最佳结果的模型,则应使用preds <- predict(clf, test, ntreelimit=clf$bestInd)