I'm trying to model a forecasting problem where I'm trying to forecast for the following month. I am using LightGBM Regressor class for it and it giving me a decent result in terms of actual Vs. predicted and mean_absolute_error. There is one category of samples in my training set that I really want to improve on and bring down the mean_absolute_error and I was thinking if I can penalize the model when it is wrong on that category of samples I might be able to achieve better results. Is there a way to pass sample weights to LGBMRegressor or any sklearn's regression class where perhaps the cost function is weighted sum of square cost function?


1 Answer 1


Yes, you pass a sample_weight to the LGBMRegressor().fit() method. See documentation on LGBMRegressor, section Methods:

enter image description here

  • $\begingroup$ thank you so much. I didn't realize that it was to be passed in the fit method. Do you know how know how LightGBM uses these weights? Will simple the Sum of sqaure error to weighted Sum of Sqaure by weighing or multiplying each sample error to its respective weight in the array? $\endgroup$ Oct 20, 2023 at 21:21
  • 1
    $\begingroup$ No, I don't think its that straitforward, according the the LightGBM paper proceedings.neurips.cc/paper_files/paper/2017/file/… it has something to do with individual sample gradients, though I failed to understand the details. $\endgroup$ Oct 21, 2023 at 22:35
  • $\begingroup$ Thank you for you help. I'll take a look. $\endgroup$ Oct 23, 2023 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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