| Total Complexity | 1 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from sklearn.model_selection import cross_val_score |
||
| 2 | from lightgbm import LGBMRegressor |
||
| 3 | from sklearn.datasets import load_diabetes |
||
| 4 | from hyperactive import Hyperactive |
||
| 5 | |||
| 6 | data = load_diabetes() |
||
| 7 | X, y = data.data, data.target |
||
| 8 | |||
| 9 | |||
| 10 | def model(opt): |
||
| 11 | lgbm = LGBMRegressor( |
||
| 12 | num_leaves=opt["num_leaves"], |
||
| 13 | bagging_freq=opt["bagging_freq"], |
||
| 14 | learning_rate=opt["learning_rate"], |
||
| 15 | ) |
||
| 16 | scores = cross_val_score(lgbm, X, y, cv=3) |
||
| 17 | |||
| 18 | return scores.mean() |
||
| 19 | |||
| 20 | |||
| 21 | search_space = { |
||
| 22 | "num_leaves": list(range(2, 50)), |
||
| 23 | "bagging_freq": list(range(2, 12)), |
||
| 24 | "learning_rate": [1e-3, 1e-2, 1e-1, 0.5, 1.0], |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | hyper = Hyperactive() |
||
| 29 | hyper.add_search(model, search_space, n_iter=20) |
||
| 30 | hyper.run() |
||
| 31 |