-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.py
73 lines (46 loc) · 1.42 KB
/
handler.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
import json
import pickle
#'Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin','BMI', 'DiabetesPedigreeFunction', 'Age'
model = pickle.load(open("Random_Forest.pkl","rb"))
def predict(event, context):
body = {
"message": "ok",
}
params = event['queryStringParameters']
pregnancies = float(params['pregnancies'])
glucose = float(params['glucose'])
BP = float(params['BP'])
SkinThickness = float(params['SkinThickness'])
Insulin = float(params['Insulin'])
BMI = float(params['BMI'])
DiabetesPedigreeFunction = float(params['DiabetesPedigreeFunction'])
Age = float(params['Age'])
input_data = [[pregnancies,glucose,BP,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age]]
pred = model.predict(input_data)[0]
body['prediction'] = int(pred)
print(params)
print("Prediction: ",pred)
response = {
"statusCode": 200,
"body": json.dumps(body),
"headers":{
"Access-Control-Allow-Origin":"*"
}
}
return response
def do_main():
event = {
"queryStringParameters":{
"pregnancies":1,
"glucose":12,
"BP":120,
"SkinThickness":1 ,
"Insulin":2,
"BMI":23,
"DiabetesPedigreeFunction":21,
"Age":54
}
}
res = predict(event,None)
print(res)
do_main()