-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoring_Script.py
More file actions
56 lines (36 loc) · 1.25 KB
/
Scoring_Script.py
File metadata and controls
56 lines (36 loc) · 1.25 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import json
import joblib
from azureml.core.model import Model
import pandas as pd
# Called when the service is loaded
def init():
global ref_cols, predictor
# Get the path to the registered model file and load it
model_path = Model.get_model_path('FirstDeployedModel')
ref_cols, predictor = joblib.load(model_path)
# Called when a request is received
def run(raw_data):
# Get the input data as a dictionary
data_dict = json.loads(raw_data)['data']
# Convert dictionary to pandas dataframe
data = pd.DataFrame.from_dict(data_dict)
# Transform the data
# data = one_hot.transform(data)
data_enc = pd.get_dummies(data)
deploy_cols = data_enc.columns
# difference of train and deploy
missing_cols = ref_cols.difference(deploy_cols)
for cols in missing_cols:
data_enc[cols] = 0
data_enc = data_enc[ref_cols]
# Get a prediction from the model
predictions = predictor.predict(data_enc)
classes = ['Default', 'No-Default']
predicted_classes = []
for prediction in predictions:
predicted_classes.append(classes[prediction])
# Return the predictions
return json.dumps(predicted_classes)