I would like to keep the objective as "reg:linear" and eval_metric as customized RMSE as follows:

def customised_rmse(preds, dtrain):
    N = len(preds)
    preds = np.array(preds)
    actual = np.array(dtrain.get_label())
    crmse = np.sqrt(np.sum(np.power((preds+1)*1.0/(actual+1) - 1.1, 2))/N)
    return "custom-rmse", crmse

When I ran, train function as follows ->

model = xgb.train(param_list, xgb_train, num_rounds, watchlist, None, customised_rmse, early_stopping_rounds=30)

Output I am getting is this ->

[0] train-rmse:15.1904  val-rmse:15.2102    train-custom-rmse:0.607681  val-custom-rmse:0.610993
Multiple eval metrics have been passed: 'val-custom-rmse' will be used for early stopping.
Will train until val-custom-rmse hasn't improved in 30 rounds.
[1] train-rmse:14.4936  val-rmse:14.5103    train-custom-rmse:0.588831  val-custom-rmse:0.589902

and so on...

My question is, it is getting optimized using "rmse" or "custom-rase" or both? What I have to do to remove "rmse" as it comes by default with "reg:linear"?


1 Answer 1


It is easier to understand if you use keyword arguments:

model = xgb.train(params=param_list, dtrain=xgb_train, 
        num_boost_round=num_rounds, evals=watchlist, obj=None, 
        feval=customised_rmse, early_stopping_rounds=30)

obj can be the objective function. feval can be the customized evaluation function.

rmse is being used to minimize error on the trainning data. However custom-rmse on the validation dataset will define when the model stop training.

Change obj to change the defult.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.