| Total Complexity | 1 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """Test module for issue #29 reproduction.""" |
||
| 2 | |||
| 3 | from sklearn.datasets import load_diabetes |
||
| 4 | from sklearn.model_selection import cross_val_score |
||
| 5 | from sklearn.tree import DecisionTreeRegressor |
||
| 6 | |||
| 7 | from hyperactive import Hyperactive |
||
| 8 | |||
| 9 | |||
| 10 | def test_issue_29(): |
||
| 11 | """Test issue 29 - accessing optimizer attributes during optimization.""" |
||
| 12 | data = load_diabetes() |
||
| 13 | X, y = data.data, data.target |
||
| 14 | |||
| 15 | def model(para): |
||
| 16 | dtr = DecisionTreeRegressor( |
||
| 17 | min_samples_split=para["min_samples_split"], |
||
| 18 | max_depth=para["max_depth"], |
||
| 19 | ) |
||
| 20 | scores = cross_val_score(dtr, X, y, cv=3) |
||
| 21 | |||
| 22 | print( |
||
| 23 | "Iteration:", |
||
| 24 | para.optimizer.nth_iter, |
||
| 25 | " Best score", |
||
| 26 | para.optimizer.best_score, |
||
| 27 | ) |
||
| 28 | |||
| 29 | return scores.mean() |
||
| 30 | |||
| 31 | search_space = { |
||
| 32 | "min_samples_split": list(range(2, 12)), |
||
| 33 | "max_depth": list(range(2, 12)), |
||
| 34 | } |
||
| 35 | |||
| 36 | hyper = Hyperactive() |
||
| 37 | hyper.add_search(model, search_space, n_iter=20) |
||
| 38 | hyper.run() |
||
| 39 |