首页 > 解决方案 > R Xgboost 验证错误作为停止指标

问题描述

我在 xgboost 二进制分类模型上使用训练和验证数据集。

params5 <- list(booster = "gbtree", objective = "binary:logistic", 
            eta=0.0001, gamma=0.5, max_depth=15, min_child_weight=1, subsample=0.6,
            colsample_bytree=0.4,seed =2222)


xgb_MOD5 <- xgb.train (params = params5, data = dtrain, nrounds = 4000,
                   watchlist = list(validation = dvalid,train = dtrain), 
                   print_every_n =30,early_stopping_rounds = 100
                  maximize = F ,serialize = TRUE)

它会自动选择火车误差作为停止指标。这导致模型在过度拟合时继续训练。

Multiple eval metrics are present. Will use train_error for early stopping.
Will train until train_error hasn't improved in 100 rounds.

如何将验证错误分配为停止指标?

标签: rxgboost

解决方案


我不使用 xgboost 的 R 绑定,并且 R-package 文档没有具体说明它。但是,python-API 文档(请参阅early_stopping_rounds参数文档)对此问题进行了相关说明:

中至少需要一项evals。如果有多个,将使用最后一个。

这里evals是评估指标的样本列表,即类似于您的watchlist论点。所以我猜,您可能只需要交换作为该参数提供的列表中的项目顺序


推荐阅读