From 12f0306f3f5275ffc0aa9ea4bb53b8ded1915185 Mon Sep 17 00:00:00 2001 From: Jordan Edwards Date: Mon, 24 Sep 2018 13:33:16 -0700 Subject: [PATCH] Create score.py --- cli/score.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cli/score.py diff --git a/cli/score.py b/cli/score.py new file mode 100644 index 00000000..cb3fccba --- /dev/null +++ b/cli/score.py @@ -0,0 +1,24 @@ +import pickle +import json +import numpy +from sklearn.externals import joblib +from sklearn.linear_model import Ridge +from azureml.core.model import Model + +def init(): + global model + # note here "sklearn_regression_model.pkl" is the name of the model registered under + # this is a different behavior than before when the code is run locally, even though the code is the same. + model_path = Model.get_model_path('sklearn_regression_model.pkl') + # deserialize the model file back into a sklearn model + model = joblib.load(model_path) + +# note you can pass in multiple rows for scoring +def run(raw_data): + try: + data = json.loads(raw_data)['data'] + data = numpy.array(data) + result = model.predict(data) + except Exception as e: + result = str(e) + return json.dumps({"result": result.tolist()})