-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpredict_meta.py
76 lines (61 loc) · 1.86 KB
/
predict_meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from sklearn.preprocessing import MinMaxScaler
import numpy as np
from joblib import dump, load
# Model="knn.joblib"
Model = "meta_models/fr.joblib"
Scaler = "meta_models/scaler.joblib"
Time_Model = "meta_models/adaboost.joblib"
classes_og = [
'sklearn.KNeighborsClassifier',
'sklearn.GaussianProcessClassifier',
'sklearn.DecisionTreeClassifier',
'sklearn.RandomForestClassifier',
'sklearn.AdaBoostClassifier',
'sklearn.GaussianNB',
'sklearn.QuadraticDiscriminantAnalysis',
'sklearn.GradientBoostingClassifier',
'sklearn.LinearDiscriminantAnalysis',
'sklearn.Perceptron',
'sklearn.LogisticRegression',
'sklearn.ComplementNB',
'sklearn.SVC']
classes = ['K Nearest Neighbors',
'Gaussian Process',
'Decision Tree', 'Random Forest',
'AdaBoost', 'Gaussian NB',
'QDA',
'Gradient Boosting',
'LDA', 'Perceptron',
'Logistic Regression', 'Complement NB',
'SVC']
excluded = [
'Gaussian Process',
'Perceptron',
'Logistic Regression',
'Complement NB']
def filter_excluded(ls):
res = []
for ent in ls:
if ent[0] in excluded:
res.append([ent[0], float(0)])
else:
res.append(ent)
return res
def predict_meta(meta):
model = load(Model)
scaler = load(Scaler)
#meta = meta[~np.isnan(meta)]
X = scaler.transform(meta.reshape(1, -1))
outp = model.predict_proba(X)[0]
srt = np.argsort(outp)[::-1]
ress = [[classes[srt[i]], float(outp[srt[i]])] for i in range(len(srt))]
ress = filter_excluded(ress) # comment this out to get full results
return ress
def predict_time(meta):
# model=load(Time_Model)
# X=meta[[0,2]].reshape(1,-1)
# outp=model.predict(X)
# print(meta)
print(meta[0], meta[2])
outp = meta[0] * meta[2] / 200
return outp