-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpredictor.py
37 lines (31 loc) · 1 KB
/
predictor.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
import sys
import numpy as np
import pandas as pd
from sklearn.externals import joblib
# get codes for prediction
dfLabels = pd.read_excel('./data/Contention_Dictionary.xlsx')
dLabels = {}
for index, row in dfLabels.iterrows():
dLabels[row['New Contention Classification Text'].lower().strip()] = row['IDs']
# load the vectorizer
vectorizer = joblib.load(filename='modelsAndTransformations/vectorizer.pkl')
# load the classifier
clf = joblib.load(filename='modelsAndTransformations/LRclf.pkl')
def main(arg=None):
if len(arg) > 1:
# Load string and clean it
text = arg[1]
text = [text.lower().strip()]
#Vectorize data
X = vectorizer.transform(text)
# predict value
y = clf.predict(X)[0]
# predict code
y_code = dLabels[clf.predict(X)[0]]
d = {text :[y, y_code]}
# print string and value
print(d)
else:
print('please include the string that needs to be scored')
if __name__ == '__main__':
main(sys.argv)