We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
first_metric_only
C++/Python/R version: Python 3.7
LightGBM version or commit hash: 2.3.0
I'm using LGBMRegressor and set metric to None and pass custom metrics to eval_metric of fit() (I refered to #2182):
LGBMRegressor
metric
None
eval_metric
fit()
model.fit( ... ... eval_metric=lambda y_true, y_pred: [my_custom_metric(y_true, y_pred)] ... )
But I don't want to use DEFAULT metric(l2) for early_stopping but first_metric_only=True flag is ALWAYS applied to this default metric!
l2
first_metric_only=True
I'd like to use my_custom_metric instead of default one for early_stopping.
my_custom_metric
Moreover, I don't want to track default metric, l2.
How can I do that?
model = lightgbm.LGBMRegressor( n_estimators=best_epoch, objective="mse", metric=None, first_metric_only=True, ) model = model.fit( _train_x, _train_y, eval_metric=lambda y_true, y_pred: [my_custom_metric(y_true, y_pred)] eval_set=[ (_train_x, _train_y,), (_valid_x, _valid_y,), ], verbose=1, early_stopping_rounds=100, )
The text was updated successfully, but these errors were encountered:
You should set metric to "None", not None.
"None"
"None" (string, not a None value) means that no metric will be registered, aliases: na, null, custom https://lightgbm.readthedocs.io/en/latest/Parameters.html#metric-parameters
from sklearn.datasets import load_boston from sklearn.metrics import mean_squared_error from sklearn.model_selection import train_test_split import lightgbm as lgb def constant_metric(y_true, y_pred): return 'error', 0, False def mse(y_true, y_pred): return 'custom MSE', mean_squared_error(y_true, y_pred), False X, y = load_boston(True) _train_x, _valid_x, _train_y, _valid_y = train_test_split(X, y, test_size=0.2) model = lgb.LGBMRegressor( n_estimators=10, objective="mse", metric='None', first_metric_only=True ) model.fit( _train_x, _train_y, eval_metric=lambda y_true, y_pred: [mse(y_true, y_pred), constant_metric(y_true, y_pred)], eval_set=[ (_train_x, _train_y,), (_valid_x, _valid_y,), ], verbose=1, early_stopping_rounds=3, )
Sorry, something went wrong.
No branches or pull requests
Environment info
C++/Python/R version: Python 3.7
LightGBM version or commit hash: 2.3.0
Error message
I'm using
LGBMRegressor
and setmetric
toNone
and pass custom metrics toeval_metric
offit()
(I refered to #2182):But I don't want to use DEFAULT metric(
l2
) for early_stopping butfirst_metric_only=True
flag is ALWAYS applied to this default metric!I'd like to use
my_custom_metric
instead of default one for early_stopping.Moreover, I don't want to track default metric,
l2
.How can I do that?
Reproducible examples
The text was updated successfully, but these errors were encountered: