Skip to content

Instantly share code, notes, and snippets.

@toshihikoyanase
Created October 29, 2020 01:16
Show Gist options
  • Save toshihikoyanase/87744ea7bea8ad5267efe02ef7950964 to your computer and use it in GitHub Desktop.
Save toshihikoyanase/87744ea7bea8ad5267efe02ef7950964 to your computer and use it in GitHub Desktop.
Regression example of LightGBMTuner
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