| Total Complexity | 3 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | from sklearn.datasets import load_iris |
||
| 6 | from sklearn.model_selection import cross_val_score |
||
| 7 | from sklearn.tree import DecisionTreeClassifier |
||
| 8 | |||
| 9 | from hyperactive import Hyperactive |
||
| 10 | |||
| 11 | data = load_iris() |
||
| 12 | X = data.data |
||
| 13 | y = data.target |
||
| 14 | memory = False |
||
| 15 | |||
| 16 | |||
| 17 | def model(para, X, y): |
||
| 18 | dtc = DecisionTreeClassifier( |
||
| 19 | max_depth=para["max_depth"], |
||
| 20 | min_samples_split=para["min_samples_split"], |
||
| 21 | min_samples_leaf=para["min_samples_leaf"], |
||
| 22 | ) |
||
| 23 | scores = cross_val_score(dtc, X, y, cv=2) |
||
| 24 | |||
| 25 | return scores.mean() |
||
| 26 | |||
| 27 | |||
| 28 | search_config = { |
||
| 29 | model: { |
||
| 30 | "max_depth": range(1, 21), |
||
| 31 | "min_samples_split": range(2, 21), |
||
| 32 | "min_samples_leaf": range(1, 21), |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | def test_results(): |
||
| 38 | opt = Hyperactive(X, y, memory=memory) |
||
| 39 | opt.search(search_config) |
||
| 40 | |||
| 41 | assert len(list(opt.results[model].keys())) == 3 |
||
| 42 | |||
| 43 | |||
| 44 | def test_best_scores(): |
||
| 45 | opt = Hyperactive(X, y, memory=memory) |
||
| 46 | opt.search(search_config) |
||
| 47 | |||
| 48 | assert 0 < opt.best_scores[model] < 1 |
||
| 49 |