| Total Complexity | 1 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from sklearn.model_selection import cross_val_score |
||
| 2 | from sklearn.ensemble import GradientBoostingClassifier |
||
| 3 | from sklearn.datasets import load_breast_cancer |
||
| 4 | from hyperactive import Hyperactive |
||
| 5 | |||
| 6 | data = load_breast_cancer() |
||
| 7 | X, y = data.data, data.target |
||
| 8 | |||
| 9 | |||
| 10 | def model(para, X, y): |
||
| 11 | model = GradientBoostingClassifier( |
||
| 12 | n_estimators=para["n_estimators"], |
||
| 13 | max_depth=para["max_depth"], |
||
| 14 | min_samples_split=para["min_samples_split"], |
||
| 15 | ) |
||
| 16 | scores = cross_val_score(model, X, y, cv=3) |
||
| 17 | |||
| 18 | return scores.mean() |
||
| 19 | |||
| 20 | |||
| 21 | search_config = { |
||
| 22 | model: { |
||
| 23 | "n_estimators": range(10, 200, 10), |
||
| 24 | "max_depth": range(2, 12), |
||
| 25 | "min_samples_split": range(2, 12), |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | # Without scatter initialization |
||
| 30 | opt = Hyperactive( |
||
| 31 | search_config, |
||
| 32 | optimizer="HillClimbing", |
||
| 33 | n_iter=10, |
||
| 34 | random_state=0, |
||
| 35 | scatter_init=False, |
||
| 36 | ) |
||
| 37 | opt.fit(X, y) |
||
| 38 | |||
| 39 | |||
| 40 | # With scatter initialization |
||
| 41 | opt = Hyperactive( |
||
| 42 | search_config, optimizer="HillClimbing", n_iter=10, random_state=0, scatter_init=10 |
||
| 43 | ) |
||
| 44 | opt.fit(X, y) |
||
| 45 |