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

tests._test_meta_learn   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Importance

Changes 0
Metric Value
wmc 3
eloc 31
dl 10
loc 51
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_metalearn() 0 3 1
A model() 10 10 1
A test_metalearn1() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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