You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move skl eval_metric and early_stopping rounds to model params. (#6751)
A new parameter `custom_metric` is added to `train` and `cv` to distinguish the behaviour from the old `feval`. And `feval` is deprecated. The new `custom_metric` receives transformed prediction when the built-in objective is used. This enables XGBoost to use cost functions from other libraries like scikit-learn directly without going through the definition of the link function.
`eval_metric` and `early_stopping_rounds` in sklearn interface are moved from `fit` to `__init__` and is now saved as part of the scikit-learn model. The old ones in `fit` function are now deprecated. The new `eval_metric` in `__init__` has the same new behaviour as `custom_metric`.
Added more detailed documents for the behaviour of custom objective and metric.
XGBoost is designed to be an extensible library. One way to extend it is by providing our
6
16
own objective function for training and corresponding metric for performance monitoring.
7
17
This document introduces implementing a customized elementwise evaluation metric and
@@ -11,12 +21,8 @@ concepts should be readily applicable to other language bindings.
11
21
.. note::
12
22
13
23
* The ranking task does not support customized functions.
14
-
* The customized functions defined here are only applicable to single node training.
15
-
Distributed environment requires syncing with ``xgboost.rabit``, the interface is
16
-
subject to change hence beyond the scope of this tutorial.
17
-
* We also plan to improve the interface for multi-classes objective in the future.
18
24
19
-
In the following sections, we will provide a step by step walk through of implementing
25
+
In the following two sections, we will provide a step by step walk through of implementing
20
26
``Squared Log Error(SLE)`` objective function:
21
27
22
28
.. math::
@@ -30,7 +36,10 @@ and its default metric ``Root Mean Squared Log Error(RMSLE)``:
30
36
Although XGBoost has native support for said functions, using it for demonstration
31
37
provides us the opportunity of comparing the result from our own implementation and the
32
38
one from XGBoost internal for learning purposes. After finishing this tutorial, we should
33
-
be able to provide our own functions for rapid experiments.
39
+
be able to provide our own functions for rapid experiments. And at the end, we will
40
+
provide some notes on non-identy link function along with examples of using custom metric
41
+
and objective with `scikit-learn` interface.
42
+
with scikit-learn interface.
34
43
35
44
*****************************
36
45
Customized Objective Function
@@ -125,24 +134,177 @@ We will be able to see XGBoost printing something like:
125
134
126
135
.. code-block:: none
127
136
128
-
[0]dtrain-PyRMSLE:1.37153dtest-PyRMSLE:1.31487
129
-
[1]dtrain-PyRMSLE:1.26619dtest-PyRMSLE:1.20899
130
-
[2]dtrain-PyRMSLE:1.17508dtest-PyRMSLE:1.11629
131
-
[3]dtrain-PyRMSLE:1.09836dtest-PyRMSLE:1.03871
132
-
[4]dtrain-PyRMSLE:1.03557dtest-PyRMSLE:0.977186
133
-
[5]dtrain-PyRMSLE:0.985783dtest-PyRMSLE:0.93057
137
+
[0]dtrain-PyRMSLE:1.37153dtest-PyRMSLE:1.31487
138
+
[1]dtrain-PyRMSLE:1.26619dtest-PyRMSLE:1.20899
139
+
[2]dtrain-PyRMSLE:1.17508dtest-PyRMSLE:1.11629
140
+
[3]dtrain-PyRMSLE:1.09836dtest-PyRMSLE:1.03871
141
+
[4]dtrain-PyRMSLE:1.03557dtest-PyRMSLE:0.977186
142
+
[5]dtrain-PyRMSLE:0.985783dtest-PyRMSLE:0.93057
134
143
...
135
144
136
145
Notice that the parameter ``disable_default_eval_metric`` is used to suppress the default metric
137
146
in XGBoost.
138
147
139
148
For fully reproducible source code and comparison plots, see `custom_rmsle.py <https://github.com/dmlc/xgboost/tree/master/demo/guide-python/custom_rmsle.py>`_.
140
149
150
+
*********************
151
+
Reverse Link Function
152
+
*********************
153
+
154
+
When using builtin objective, the raw prediction is transformed according to the objective
155
+
function. When custom objective is provided XGBoost doesn't know its link function so the
156
+
user is responsible for making the transformation for both objective and custom evaluation
157
+
metric. For objective with identiy link like ``squared error`` this is trivial, but for
158
+
other link functions like log link or inverse link the difference is significant.
159
+
160
+
For the Python package, the behaviour of prediction can be controlled by the
161
+
``output_margin`` parameter in ``predict`` function. When using the ``custom_metric``
162
+
parameter without a custom objective, the metric function will receive transformed
163
+
prediction since the objective is defined by XGBoost. However, when custom objective is
164
+
also provided along with that metric, then both the objective and custom metric will
165
+
recieve raw prediction. Following example provides a comparison between two different
166
+
behavior with a multi-class classification model. Firstly we define 2 different Python
167
+
metric functions implementing the same underlying metric for comparison,
168
+
`merror_with_transform` is used when custom objective is also used, otherwise the simpler
169
+
`merror` is preferred since XGBoost can perform the transformation itself.
0 commit comments