How to write a custom evaluation metric in python for xgboost?
<p>I would like to add the kappa evaluation metric to use in xgboost in Python. I am having trouble understanding how to connect a Python function with xgboost.</p>

<p>According to the xgboost documentation, a "User can add multiple evaluation metrics, for python user, remember to pass the metrics in as list of parameters pairs instead of map, so that latter ‘eval_metric’ won’t override previous one"</p>

<p>This has been raised in <a href="https://github.com/dmlc/xgboost/issues/1152" rel="noreferrer">xgboost's github page</a> for R but not for Python.</p>

<p>For example if the kappa function is:</p>

<pre><code>def kappa(preds, y):
    # perform kappa calculation
    return score
</code></pre>

<p>How do I go about implementing it with xgboost?
Specifing <code>'kappa'</code> as a string in the <code>eval_metric</code> parameter
results in <code>XGBoostError: unknown evaluation metric type: kappa</code>. </p>

<p>Likewise specifying the kappa method object results in <code>XGBoostError: unknown evaluation metric type: &lt;function kappa at 0x7fbef4b03488&gt;</code>.</p>

<p>How can a custom evaluation metric be used in xgboost in python?</p>