-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPrediction.py
45 lines (37 loc) · 1.11 KB
/
testPrediction.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
from __future__ import print_function
import boto3
import sys
ml = boto3.client('machinelearning')
model_id=None
try:
response = ml.describe_ml_models(
FilterVariable='Name',
EQ='ShoppingCartModel'
)
for model in response['Results']:
if model['Status'] != 'DELETED' and model['Status'] != 'FAILED':
model_id=model['MLModelId']
endpoint=model['EndpointInfo']['EndpointUrl']
except:
print("No model ready")
sys.exit()
if model_id != None:
prediction = ml.predict(
MLModelId=model_id,
Record={
'customer': '4634',
'cart': '13661535770434',
'duration': '761',
'added': '9',
'removed': '1',
'thinking': '0',
'productsadded': '8956-10134-10229-6903-8714-13720-6297-10636-8966',
'productsremoved': '8956',
'productlist': '10134-10229-6903-8714-13720-6297-10636-8966',
'timestamp': '1464000379'
},
PredictEndpoint=endpoint
)
print(prediction['Prediction'])
else:
print("No model ready")