Skip to content

Instantly share code, notes, and snippets.

@sofianhamiti
Created March 14, 2021 17:34
Show Gist options
  • Save sofianhamiti/4e5abac71472412f6a692f15d356f252 to your computer and use it in GitHub Desktop.
Save sofianhamiti/4e5abac71472412f6a692f15d356f252 to your computer and use it in GitHub Desktop.
import os
import json
import xgboost
import pandas as pd
import pickle as pkl
from utils import extract_model
# download model file from S3 into /tmp folder
extract_model(os.environ['MODEL_S3_URI'], '/tmp')
# LOAD MODEL
model = pkl.load(open('/tmp/xgboost-model', 'rb'))
def handler(event, context):
# TRANSFORM DATA
body = json.loads(event['body'])
df = pd.DataFrame(body, index=[0])
data = xgboost.DMatrix(df.values)
# PREDICT
prediction = model.predict(data)
return {
'prediction': str(prediction)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment