Completed
Push — master ( 6c8f7d...da8f19 )
by Simon
02:46
created

tests._test_meta_learn.model()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 8
dl 10
loc 10
rs 10
c 0
b 0
f 0
cc 1
nop 3
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
from hyperactive import Hyperactive
9
from hyperactive import MetaLearn
10
11
data = load_iris()
12
X = data.data
13
y = data.target
14
15
16 View Code Duplication
def model(para, X_train, y_train):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
    model = DecisionTreeClassifier(
18
        criterion=para["criterion"],
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(model, X_train, y_train, cv=3)
24
25
    return scores.mean(), model
26
27
28
search_config = {
29
    model: {
30
        "criterion": ["gini", "entropy"],
31
        "max_depth": range(1, 21),
32
        "min_samples_split": range(2, 21),
33
        "min_samples_leaf": range(1, 21),
34
    }
35
}
36
37
38
def test_metalearn():
39
    ml = MetaLearn(search_config)
40
    ml.collect(X, y)
41
    # ml.train()
42
    # ml.search(X, y)
43
44
45
def test_metalearn1():
46
    opt = Hyperactive(search_config, meta_learn=True)
47
    opt.fit(X, y)
48
49
50
test_metalearn()
51