Passed
Push — master ( b478a2...16a37b )
by Simon
01:57 queued 10s
created

hyperactive.model.Model.train_model()   A

Complexity

Conditions 5

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nop 2
dl 0
loc 19
rs 9.1832
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import time
6
import numpy as np
7
8
9
class Model:
10
    def __init__(self, func_, nth_process, _main_args_):
11
        self.func_ = func_
12
        self.nth_process = nth_process
13
        self.X = _main_args_.X
14
        self.y = _main_args_.y
15
16
    def train_model(self, para_dict):
17
        start_time = time.time()
18
        results = self.func_(para_dict, self.X, self.y)
19
        eval_time = time.time() - start_time
20
21
        if isinstance(results, tuple):
22
            score = results[0]
23
            model = results[1]
24
        elif (
25
            isinstance(results, float)
26
            or isinstance(results, np.float64)
27
            or isinstance(results, np.float32)
28
        ):
29
            score = results
30
            model = None
31
        else:
32
            print("Error: model function must return float or tuple")
33
34
        return score, eval_time, model
0 ignored issues
show
introduced by
The variable model does not seem to be defined for all execution paths.
Loading history...
introduced by
The variable score does not seem to be defined for all execution paths.
Loading history...
35