Skip to content

Commit 12f0306

Browse files
authored
Create score.py
1 parent 2817a77 commit 12f0306

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cli/score.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pickle
2+
import json
3+
import numpy
4+
from sklearn.externals import joblib
5+
from sklearn.linear_model import Ridge
6+
from azureml.core.model import Model
7+
8+
def init():
9+
global model
10+
# note here "sklearn_regression_model.pkl" is the name of the model registered under
11+
# this is a different behavior than before when the code is run locally, even though the code is the same.
12+
model_path = Model.get_model_path('sklearn_regression_model.pkl')
13+
# deserialize the model file back into a sklearn model
14+
model = joblib.load(model_path)
15+
16+
# note you can pass in multiple rows for scoring
17+
def run(raw_data):
18+
try:
19+
data = json.loads(raw_data)['data']
20+
data = numpy.array(data)
21+
result = model.predict(data)
22+
except Exception as e:
23+
result = str(e)
24+
return json.dumps({"result": result.tolist()})

0 commit comments

Comments
 (0)