Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | import os |
||
6 | import numpy as np |
||
7 | |||
8 | from sklearn.externals import joblib |
||
9 | |||
10 | |||
11 | def find_best_hyperpara(features, scores): |
||
12 | N_best_features = 1 |
||
13 | |||
14 | scores = np.array(scores) |
||
15 | index_best_scores = list(scores.argsort()[-N_best_features:][::-1]) |
||
16 | |||
17 | best_score = scores[index_best_scores][0] |
||
18 | best_features = features.iloc[index_best_scores] |
||
19 | |||
20 | return best_features, best_score |
||
21 | |||
22 | |||
23 | class Predictor: |
||
24 | def __init__(self): |
||
25 | pass |
||
26 | |||
27 | def search(self, X_test): |
||
28 | best_para, best_score = self._predict(X_test) |
||
29 | return best_para, best_score |
||
30 | |||
31 | def load_model(self, path): |
||
32 | if os.path.isfile(path): |
||
33 | self.meta_reg = joblib.load(path) |
||
34 | else: |
||
35 | print("File at path", path, "not found") |
||
36 | |||
37 | def _predict(self, X_test): |
||
38 | score_pred = self.meta_reg.predict(X_test) |
||
39 | best_features, best_score = find_best_hyperpara(X_test, score_pred) |
||
40 | |||
41 | return best_features, best_score |
||
42 |