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
I am trying to exclude some training observations by giving them a weight of zero through the "sample_weights" argument.
As I understand it, observations with a weight of 0 do not influence the training, so changes in their values should not affect the resulting model. However, this is not what I see if I train two models, each one with different values in the samples with weight of zero.
Does anyone know how exactly the algorithm implements sample weight inside the code?
Thanks a lot!
Reproducible example
import numpy as np
from lightgbm import LGBMRegressor
rng = np.random.default_rng(12345)
X_train = rng.normal(size=(100, 3))
y_train = rng.normal(loc=10, size=(100, 1)).ravel()
X_test = rng.normal(size=(5, 3))
weights = np.repeat([0, 1], repeats=[10, 90]) # First 10 samples have zero weight
regressor = LGBMRegressor(random_state=123)
regressor.fit(X=X_train, y=y_train, sample_weight=weights)
regressor.predict(X=X_test)
Hi @JoaquinAmatRodrigo, thanks for using LightGBM. The weights are used when computing the gradients and hessians. By setting a zero weight you're basically ignoring the errors for those samples. However, the feature values for those samples are still considered when building the feature histograms, that's why you end up with different models.
If you instead modified the target values you should get the same results, e.g.:
Description
Hello,
I am trying to exclude some training observations by giving them a weight of zero through the "sample_weights" argument.
As I understand it, observations with a weight of 0 do not influence the training, so changes in their values should not affect the resulting model. However, this is not what I see if I train two models, each one with different values in the samples with weight of zero.
Does anyone know how exactly the algorithm implements sample weight inside the code?
Thanks a lot!
Reproducible example
array([10.19829764, 10.72541724, 9.65296611, 9.29206054, 9.77377765])
array([10.3309465 , 10.5325829 , 9.54558229, 9.47538141, 9.83769447])
Environment info
'3.3.2'
Command(s) you used to install LightGBM
The text was updated successfully, but these errors were encountered: