forked from csiebler/azure-machine-learning-mlops-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
score_parallel.py
54 lines (41 loc) · 1.34 KB
/
score_parallel.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
import os
import glob
import json
import argparse
import numpy as np
import pandas as pd
import joblib
from azureml.core.model import Model
from azureml.core import Run
current_run = None
model = None
def init():
print("Started batch scoring by running init()")
parser = argparse.ArgumentParser()
parser.add_argument('--model_name', type=str, help='Model to use for batch scoring')
args, _ = parser.parse_known_args()
global current_run
current_run = Run.get_context()
print(f'Arguments: {args}')
print(f'Model name: {args.model_name}')
global model
model_path = Model.get_model_path(args.model_name)
model = joblib.load(model_path)
def run(file_list):
try:
output_df = pd.DataFrame(columns=["Sno", "ProbaGoodCredit", "ProbaBadCredit"])
for filename in file_list:
df = pd.read_csv(filename)
sno = df["Sno"]
df = df.drop("Sno", axis=1)
proba = model.predict_proba(df)
proba = pd.DataFrame(data=proba, columns=["ProbaGoodCredit", "ProbaBadCredit"])
result = pd.concat([sno, proba], axis=1)
output_df = output_df.append(result)
print(f'Batch scored: {filename}')
return output_df
except Exception as e:
error = str(e)
return error
if __name__ == "__main__":
test()