L Xandor
L Xandor

Reputation: 1841

How to set eval metrics for xgboost.train?

How can I set xgboost.train to opitimize for a specific evaluation metric similar to how I can set xgboost.fit(eval_metric = 'auc')?

Upvotes: 3

Views: 32391

Answers (2)

Soerendip
Soerendip

Reputation: 9148

You have to set it in the parameters.

E.g.:

params = {
 'objective': 'multi:softprob',
 'tree_method': 'gpu_hist',
 'num_class': 27,
 'seed': 0,
 'max_depth': 2,
 'colsample_bytree': 0.36524046160303747,
 'colsample_bylevel': 0.7008644188368828,
 'grow_policy': 'lossguide',
 'lambda': 1-08,
 'alpha': 0.1,
 'subsample': 0.9,
 'eta': 0.01,
 'eval_metric': 'merror'}

xgb.train(params, dX_train, 
          num_boost_round=100, 
          verbose_eval=10, 
          early_stopping_rounds=10, 
          evals=[(dX_train, 'train') , (dX_valid, 'valid')],
          )

Upvotes: 1

null
null

Reputation: 2137

See the document here. Where you can find metrics xgboost support under eval_metric.

If you want to use a custom objective function or metric see here.

Upvotes: 2

Related Questions