Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | import time |
||
6 | import numbers |
||
7 | |||
8 | |||
9 | def is_numeric(variable): |
||
10 | return isinstance(variable, numbers.Number) |
||
11 | |||
12 | |||
13 | class Model: |
||
14 | def __init__(self, model, func_para, verb): |
||
15 | self.model = model |
||
16 | self.func_para = func_para |
||
17 | self.verb = verb |
||
18 | |||
19 | def eval(self, para_dict): |
||
20 | if self.func_para is not None: |
||
21 | para_dict = {**para_dict, **self.func_para} |
||
22 | |||
23 | results_dict = {} |
||
24 | |||
25 | start_time = time.time() |
||
26 | results = self.model(para_dict) |
||
27 | eval_time = time.time() - start_time |
||
28 | |||
29 | if isinstance(results, dict): |
||
30 | if "score" not in results: |
||
31 | print("Error: model function must return dict with score-keyword") |
||
32 | |||
33 | results_dict = results |
||
34 | if "eval_time" not in results_dict: |
||
35 | results_dict["eval_time"] = eval_time |
||
36 | |||
37 | else: |
||
38 | results_dict["score"] = results |
||
39 | results_dict["eval_time"] = eval_time |
||
40 | |||
41 | if is_numeric(results_dict["score"]): |
||
42 | return results_dict |
||
43 | else: |
||
44 | print("Error: model function must return numeric variable") |
||
45 |