Fix #3598: document that custom objective can't contain colon (:) (#3601)

This commit is contained in:
Philip Hyunsu Cho 2018-08-16 19:05:40 -07:00 committed by GitHub
parent caf4a756bf
commit ac7fc1306b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,10 @@ def logregobj(preds, dtrain):
# Take this in mind when you use the customization, and maybe you need write customized evaluation function
def evalerror(preds, dtrain):
labels = dtrain.get_label()
# return a pair metric_name, result
# return a pair metric_name, result. The metric name must not contain a colon (:)
# since preds are margin(before logistic transformation, cutoff at 0)
return 'error', float(sum(labels != (preds > 0.0))) / len(labels)
# training with customized objective, we can also do step by step training
# simply look at xgboost.py's implementation of train
bst = xgb.train(param, dtrain, num_round, watchlist, logregobj, evalerror)
bst = xgb.train(param, dtrain, num_round, watchlist, obj=logregobj, feval=evalerror)