-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.py
More file actions
43 lines (36 loc) · 1.38 KB
/
Copy pathscore.py
File metadata and controls
43 lines (36 loc) · 1.38 KB
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
# score.py
import joblib
import numpy as np
import json
from azureml.core.model import Model
# score.py
import joblib
import numpy as np
import json
from azureml.core.model import Model
def init():
global model
model_path = Model.get_model_path("pimadiabetes_logistic_regression_model")
model = joblib.load(model_path)
def run(raw_data):
try:
data = np.array(json.loads(raw_data)['data'])
prediction = model.predict(data)
results = []
for pred in prediction:
if pred == 1:
result = {
"prediction": int(pred),
"message": "❗ You are predicted to be at HIGH risk of diabetes.\n",
"explanation": "Prediction based on factors such as: Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreeFunction, Age."
}
else:
result = {
"prediction": int(pred),
"message": "✅ You are predicted to be at LOW risk of diabetes.\n",
"explanation": "Prediction based on factors such as: Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreeFunction, Age."
}
results.append(result)
return results if len(results) > 1 else results[0]
except Exception as e:
return {"error": str(e)}