4
$\begingroup$

I'm using the newest version of xgboost package in python 2.7 and based on my problem, I'm going to change xgboost cost function to use my own defined cost function. Couple of questions:

In which part of the xgboost package should I find and change the cost function? After changing the cost function, how can I add the updated code to the xgboost package to use the new training function instead of xgboost's pre-defined function?

| improve this question | | | | |
$\endgroup$
  • 2
    $\begingroup$ Reading the docs will help $\endgroup$ – Aditya Apr 22 '18 at 2:10
4
$\begingroup$

This is discussed in stackoverflow, just to recap:

Define your your customized cost function, e.g.:

 def new_cost(y_pred, y_true):
    # perform calculation for new cost
    return 'new_cost', score

Then pass it to the feval argument (see official doc) for training like:

model = xgboost.train(params, dtrain, num_rounds, watchlist, feval=new_cost)

There are many examples out there if you search harder for more concrete use cases.

| improve this answer | | | | |
$\endgroup$
0
$\begingroup$

feval is used for customized evaluation function. feval (function) – Customized evaluation function.

For defining customized cost function use obj (function) – Customized objective function.

| improve this answer | | | | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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