Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscore.py
More file actions
Latest commit
33 lines (29 loc) · 886 Bytes
/
Copy pathscore.py
File metadata and controls
33 lines (29 loc) · 886 Bytes
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
# initialize the scoring logic by loading the model
definit():
importnumpy
importscipy
fromsklearn.linear_modelimportLogisticRegression
globalmodel
importpickle
# load model file
f=open('model.pkl', 'rb')
# deserialize it into a scikit-learn model
model=pickle.load(f)
f.close()
defrun(inputString):
importjson
importnumpy
try:
input_list=json.loads(inputString)
exceptValueError:
return"bad input: expecting a JSON encoded list of lists."
input_array=numpy.array(input_list)
if (input_array.shape!= (1, 4)):
return'bad input: expecting a JSON encoded list of lists of shape (1,4).'
# make prediction
score=model.predict(input_array)[0]
returnstr(score)
if__name__=='__main__':
importjson
init()
print (run(json.dumps([[1,2,3,4]])))