Lightgbm: eval_class_weight usage in sklearn interface

Created on 4 Sep 2018  Â·  4Comments  Â·  Source: microsoft/LightGBM

I fail to find info on usage of the eval_class_weight argument in the LGBMModel.fit() method and it's interplay with the class_weight attribute in the constructor.

The docs say

eval_class_weight (list or None, optional (default=None)) – Class weights of eval data.

But it does not say what should be elements of the list (dictionaries similar to class_weight one per evaluation sample?). It is also unclear if the class_weight weights are applied in metric calculation or not, in particular, if the training sample is in the evaluation list.

Thanks in advance for any feedback

Most helpful comment

Thanks a lot. This clarifies the usage of the feature.

All 4 comments

Hi Misha!

class_weight was introduced in #1114. Also, the discussion in #1107 can be helpful.

But it does not say what should be elements of the list (dictionaries similar to class_weight one per evaluation sample?).

Yes, eval_class_weight can be a list with the following elements: dictionaries, 'balanced' strings or Nones. Just like class_weight constructor argument.

It is also unclear if the class_weight weights are applied in metric calculation or not, in particular, if the training sample is in the evaluation list.

I think that the code can explain better than words.
https://github.com/Microsoft/LightGBM/blob/5442aa97d71491cb738fa98c1d69a40760db593b/python-package/lightgbm/sklearn.py#L477-L486

Training data is ignored if it's in the evaluation list:
https://github.com/Microsoft/LightGBM/blob/5442aa97d71491cb738fa98c1d69a40760db593b/python-package/lightgbm/sklearn.py#L477-L478

eval_class_weight is transformed into sample weights here
https://github.com/Microsoft/LightGBM/blob/5442aa97d71491cb738fa98c1d69a40760db593b/python-package/lightgbm/sklearn.py#L482
(you can find how it is done here https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/class_weight.py)
and then transformed values either are multiplied with values from eval_sample_weight (if specified)
https://github.com/Microsoft/LightGBM/blob/5442aa97d71491cb738fa98c1d69a40760db593b/python-package/lightgbm/sklearn.py#L486
or are passed like the ordinary sample weights
https://github.com/Microsoft/LightGBM/blob/5442aa97d71491cb738fa98c1d69a40760db593b/python-package/lightgbm/sklearn.py#L484

Thanks a lot. This clarifies the usage of the feature.

Hello, I am new to GBDT.
I want to know how to use class_weight .
I know in binary classification scale_pos_weight can be set as num_class1/num_class2, but it can be use only in binary.

used only in binary application

https://github.com/Microsoft/LightGBM/blob/master/docs/Parameters.rst#weight_column
I find there is another parameter in multi-class, weight_column .

default = "", type = int or string, aliases: weight

Where can I find how exactly these weight are used, is there a example?
Thanks a lot!

@pjgao Please read this paragraph. It's the same as weight_column
https://github.com/Microsoft/LightGBM/blob/master/docs/Parameters.rst#weight-data

Was this page helpful?
0 / 5 - 0 ratings