Code Duplication    Length = 33-33 lines in 2 locations

examples/examples_v1.x.x/use_cases/meta_opt_example.py 1 location

@@ 11-43 (lines=33) @@
8
X, y = data.data, data.target
9
10
11
def meta_opt(para, X, y):
12
    def model(para, X, y):
13
        model = DecisionTreeClassifier(
14
            max_depth=para["max_depth"],
15
            min_samples_split=para["min_samples_split"],
16
            min_samples_leaf=para["min_samples_leaf"],
17
        )
18
        scores = cross_val_score(model, X, y, cv=3)
19
20
        return scores.mean()
21
22
    search_config = {
23
        model: {
24
            "max_depth": range(2, 50),
25
            "min_samples_split": range(2, 50),
26
            "min_samples_leaf": range(1, 50),
27
        }
28
    }
29
30
    opt = Hyperactive(
31
        search_config,
32
        optimizer={
33
            "ParticleSwarm": {
34
                "inertia": para["inertia"],
35
                "cognitive_weight": para["cognitive_weight"],
36
                "social_weight": para["social_weight"],
37
            }
38
        },
39
        verbosity=None,
40
    )
41
    opt.search(X, y)
42
43
    return opt.score_best
44
45
46
search_config = {

examples/use_cases/MetaOptimization.py 1 location

@@ 11-43 (lines=33) @@
8
X, y = data.data, data.target
9
10
11
def meta_opt(para, X, y):
12
    def model(para, X, y):
13
        model = DecisionTreeClassifier(
14
            max_depth=para["max_depth"],
15
            min_samples_split=para["min_samples_split"],
16
            min_samples_leaf=para["min_samples_leaf"],
17
        )
18
        scores = cross_val_score(model, X, y, cv=3)
19
20
        return scores.mean()
21
22
    search_config = {
23
        model: {
24
            "max_depth": range(2, 50),
25
            "min_samples_split": range(2, 50),
26
            "min_samples_leaf": range(1, 50),
27
        }
28
    }
29
30
    opt = Hyperactive(
31
        search_config,
32
        optimizer={
33
            "ParticleSwarm": {
34
                "inertia": para["inertia"],
35
                "cognitive_weight": para["cognitive_weight"],
36
                "social_weight": para["social_weight"],
37
            }
38
        },
39
        verbosity=None,
40
    )
41
    opt.search(X, y)
42
43
    return opt.score_best
44
45
46
search_config = {