-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weight vectors for train and evaluation in lightgbm.cv #5797
Comments
Sorry for the long delay in responding. I'm not sure if you mean that
This example demonstrates both of those things: import lightgbm as lgb
import numpy as np
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=10_000)
weights = np.random.default_rng().uniform(size=y.shape)
dtrain = lgb.Dataset(
data=X,
label=y,
weight=weights
)
def _weighted_mae(preds, train_data):
weights = train_data.get_weight()
y_true = train_data.get_label()
# NOTE: you may want to normalize these weights to be in [0.0, 1.0]
# to make this a bit easier to interpret
metric = weights * np.abs(y_true - preds)
higher_better = False
return ("weighted_mae", metric, higher_better)
results = lgb.cv(
params={
"objective": "regression",
"metric": ["mae"]
},
train_set=dtrain,
num_boost_round=10,
nfold=3,
stratified=False,
return_cvbooster=False,
feval=_weighted_mae
)
# view metrics
import pandas as pd
pd.DataFrame(results) |
Summary
Currently
lightgbm.cv
cannot cross-validate according to a weight schemeMotivation
This leads to better performance ;). Can better align your training to include recency heuristics.
Description
lightgbm.cv
should take two additional parameterstraining_weights: Series|Array
andeval_weights: List[Series|Array]
len(eval_weights)
should be equal tolen(metrics)
len(training_weights)
should be equal tolen(eval_weights[i])
should be equal to number of training samples intrain_set
training_weights
would providesample_weight
andeval_weights
would provideeval_sample_weight
References
The text was updated successfully, but these errors were encountered: