Created
June 5, 2020 07:08
-
-
Save korkridake/a2700cfbb507f9e6b9398a824ff97e3f to your computer and use it in GitHub Desktop.
MLOps Ep.4 Productionizing Scoring Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%writefile score.py | |
import json | |
import numpy as np | |
import os | |
import pickle | |
import joblib | |
def init(): | |
global model | |
################################################################################################## | |
# AZUREML_MODEL_DIR is an environment variable created during deployment. | |
# It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION) | |
# For multiple models, it points to the folder containing all deployed models (./azureml-models) | |
################################################################################################## | |
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl') | |
model = joblib.load(model_path) | |
def run(raw_data): | |
data = np.array(json.loads(raw_data)['data']) | |
# make prediction | |
y_hat = model.predict(data) | |
# you can return any data type as long as it is JSON-serializable | |
return y_hat.tolist() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment