Skip to content
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

Can't reproduce L1-score #2112

Closed
MarcoGorelli opened this issue Apr 17, 2019 · 1 comment
Closed

Can't reproduce L1-score #2112

MarcoGorelli opened this issue Apr 17, 2019 · 1 comment

Comments

@MarcoGorelli
Copy link

Environment info

Operating System: Linux 64-bit

CPU/GPU model:

C++/Python/R version: 3.7.3

LightGBM version or commit hash: 2.2.1

Reproducible examples

When I run LGBM with early stopping, it gives me the scores corresponding to its best iteration.

When I try to reproduce these scores myself, I get different numbers.

import lightgbm as lgb
from sklearn.datasets import load_breast_cancer
import pandas as pd
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import KFold


data = load_breast_cancer()
X = pd.DataFrame(data.data)
y = pd.Series(data.target)

lgb_params =  {'boosting_type': 'dart', 'random_state': 42}

folds = KFold(5)

for train_idx, val_idx in folds.split(X):
    X_train, X_valid = X.iloc[train_idx], X.iloc[val_idx]
    y_train, y_valid = y.iloc[train_idx], y.iloc[val_idx]
    model = lgb.LGBMRegressor(**lgb_params, n_estimators=10000, n_jobs=-1)
    model.fit(X_train, y_train,
              eval_set=[(X_valid, y_valid)],
              eval_metric='mae', verbose=-1, early_stopping_rounds=200)
    y_pred_valid = model.predict(X_valid)
    print(mean_absolute_error(y_valid, y_pred_valid))

I was expecting that

valid_0's l1: 0.123608

would match my own calculation from mean_absolute_error, but it doesn't. Indeed, here is the top part of my output:

Training until validation scores don't improve for 200 rounds.
Early stopping, best iteration is:
[631]	valid_0's l2: 0.0515033	valid_0's l1: 0.123608
0.16287265537021847
@guolinke
Copy link
Collaborator

dart cannot be used with early stopping.
refer to #1893

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants