tests.test_issues.test_issue_29   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_issue_29() 0 28 1
1
from sklearn.datasets import load_diabetes
2
from sklearn.tree import DecisionTreeRegressor
3
from sklearn.model_selection import cross_val_score
4
5
from hyperactive import Hyperactive
6
7
8
def test_issue_29():
9
    data = load_diabetes()
10
    X, y = data.data, data.target
11
12
    def model(para):
13
        dtr = DecisionTreeRegressor(
14
            min_samples_split=para["min_samples_split"],
15
            max_depth=para["max_depth"],
16
        )
17
        scores = cross_val_score(dtr, X, y, cv=3)
18
19
        print(
20
            "Iteration:",
21
            para.optimizer.nth_iter,
22
            " Best score",
23
            para.optimizer.best_score,
24
        )
25
26
        return scores.mean()
27
28
    search_space = {
29
        "min_samples_split": list(range(2, 12)),
30
        "max_depth": list(range(2, 12)),
31
    }
32
33
    hyper = Hyperactive()
34
    hyper.add_search(model, search_space, n_iter=20)
35
    hyper.run()
36