-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathtuning_lightgbm.py
40 lines (29 loc) · 1.01 KB
/
tuning_lightgbm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# License: MIT
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_digits
from openbox import get_config_space, get_objective_function
from openbox import Optimizer
if __name__ == "__main__":
# prepare your data
X, y = load_digits(return_X_y=True)
x_train, x_val, y_train, y_val = train_test_split(X, y, test_size=0.2, stratify=y, random_state=1)
# get config_space and objective_function
config_space = get_config_space('lightgbm')
objective_function = get_objective_function('lightgbm', x_train, x_val, y_train, y_val)
# run
opt = Optimizer(
objective_function,
config_space,
max_runs=100,
surrogate_type='prf',
time_limit_per_trial=180,
task_id='tuning_lightgbm',
)
history = opt.run()
print(history)
history.plot_convergence()
plt.show()
# install pyrfr to use get_importance()
print(history.get_importance())
# history.visualize_jupyter()