Search code examples
lightgbm

LightGbm: how to use eval_sample_weight


I am working on a binary classification problem in LightGbm (Scikit-learn API), and have a problem understanding how to include sample weights. My code currently looks like this

classifier = LGBMClassifier(n_estimators=100, learning_rate = 0.1, num_leaves = 15)    
classifier.fit(X_train, y_train, sample_weight = w_train, eval_set = (X_val, y_val))

Here w_train is a numpy array with the same dimension as y_train. But I need LightGbm to also use sample_weights on the validation set, so I set eval_sample_weight in the fit function. I expected this to also be an array w_val (with the same dimension as y_val), but I see from the documentation that this is a list of arrays. I can not find any examples using this, so I struggle to understand why. To my understanding, this should just be a weight for each element in the validation set. A list of arrays: would this mean multiple weights for each sample? Can anyone explain?


Solution

  • Figured this out myself. LightGbm accepts a list of validation sets. So, it also of course accepts a list of weights. One set of weights for each validation set.