Passed
Push — master ( 75ea99...9efe12 )
by Simon
02:17
created

tests.test_methods   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Importance

Changes 0
Metric Value
wmc 2
eloc 30
dl 10
loc 47
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_get_results() 0 8 1
A model() 10 10 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
10
data = load_iris()
11
X = data.data
12
y = data.target
13
14
n_iter = 1
15
16
17 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...
18
    model = DecisionTreeClassifier(
19
        criterion=para["criterion"],
20
        max_depth=para["max_depth"],
21
        min_samples_split=para["min_samples_split"],
22
        min_samples_leaf=para["min_samples_leaf"],
23
    )
24
    scores = cross_val_score(model, X_train, y_train, cv=2)
25
26
    return scores.mean()
27
28
29
search_config = {
30
    model: {
31
        "criterion": ["gini", "entropy"],
32
        "max_depth": range(1, 11),
33
        "min_samples_split": range(2, 11),
34
        "min_samples_leaf": range(1, 11),
35
    }
36
}
37
38
39
def test_get_results():
40
    opt = Hyperactive(search_config, n_iter=n_iter, optimizer="HillClimbing")
41
    opt.search(X, y)
42
    opt.get_results()
43
44
    opt = Hyperactive(search_config, n_iter=n_iter, n_jobs=2, optimizer="HillClimbing")
45
    opt.search(X, y)
46
    opt.get_results()
47