Created
October 29, 2020 01:16
-
-
Save toshihikoyanase/87744ea7bea8ad5267efe02ef7950964 to your computer and use it in GitHub Desktop.
Regression example of LightGBMTuner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sklearn.datasets | |
from sklearn.model_selection import train_test_split | |
import optuna.integration.lightgbm as lgb | |
if __name__ == "__main__": | |
X, y = sklearn.datasets.load_boston(return_X_y=True) | |
train_x, val_x, train_y, val_y = train_test_split(X, y, test_size=0.25) | |
dtrain = lgb.Dataset(train_x, label=train_y) | |
dval = lgb.Dataset(val_x, label=val_y) | |
params = { | |
"objective": "binary", | |
"metric": "gamma", | |
"verbosity": -1, | |
"boosting_type": "gbdt", | |
} | |
model = lgb.train( | |
params, dtrain, valid_sets=[dtrain, dval], verbose_eval=100, early_stopping_rounds=100 | |
) | |
best_params = model.params | |
print("Best params:", best_params) | |
print(" Params: ") | |
for key, value in best_params.items(): | |
print(" {}: {}".format(key, value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment