小编Nic*_*zko的帖子

XGBoost 提前停止给出 KeyError: 'best_msg'

我正在尝试使用 XGBoost scikit 包装器在回归问题中提前停止。奇怪的是,提前停止的计算eval_metric(在我的例子中,rmse)在每early stopping一轮都失败了。这很奇怪,因为相同的估计器确实适用于eval_setwithout early stopping

这是代码:

eval_train_indices=y.dropna()[:-n_splits].index
eval_test_indices=y.dropna()[-n_splits:].index

X_train, X_test=X.loc[eval_train_indices,:], X.loc[eval_test_indices,:]
y_train, y_test = y.loc[eval_train_indices], y.loc[eval_test_indices]

eval_set = [(X_train, y_train), (X_test, y_test)]

predictor=XGBRegressor(n_estimators = 50000, subsample=0.8, **{params})

predictor.fit(X, y,
                  eval_metric=["rmse"], 
                  eval_set=eval_set, 
                  early_stopping_rounds=40,
                  verbose=True)
Run Code Online (Sandbox Code Playgroud)

它产生的错误消息:

    <ipython-input-65-358402bfa21c> in fit(self, T)
    147                   early_stopping_rounds=40,
    148                   verbose=True)
    150 
    151         n_estimators=int(self.predictor.best_iteration*1.0)

/Users/Nicolas/anaconda2/lib/python2.7/site-packages/xgboost-0.7-py2.7.egg/xgboost/sklearn.pyc in fit(self, X, y, sample_weight, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model)
    291                               early_stopping_rounds=early_stopping_rounds,
    292                               evals_result=evals_result, obj=obj, feval=feval,
--> 293                               verbose_eval=verbose, xgb_model=xgb_model)
    294 
    295         if …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn xgboost

5
推荐指数
1
解决办法
3185
查看次数

标签 统计

python ×1

scikit-learn ×1

xgboost ×1