Created
March 14, 2021 17:34
-
-
Save sofianhamiti/4e5abac71472412f6a692f15d356f252 to your computer and use it in GitHub Desktop.
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
| 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