Skip to content

Dictionary key referenced before assignment during early stop #5424

@mjkohl32

Description

@mjkohl32

When running xgboost.cv with early stopping rounds, after a few iterations the code breaks from a KeyError on the line below. There's some situation where state['bst_msg'] is not yet assigned, perhaps because it isn't set in init.

KeyError: 'best_msg'

best_msg = state['best_msg']

I was running my code with nrounds=500 and early_stopping_rounds=20 (though I've run it in the range of 10 to 200 early_stopping_rounds).

bst_cv = xgb.cv(params, dtrain, 500, nfold = 5, shuffle=True, early_stopping_rounds=20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions