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

hyperactive.model   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Model.train_model() 0 19 5
A Model.__init__() 0 5 1
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