Last active
February 16, 2021 18:05
-
-
Save sofianhamiti/ae88299271996974bb66a03b9cf86ddd 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 boto3 | |
| import joblib | |
| import pandas as pd | |
| # download model file from S3 into /tmp folder | |
| s3 = boto3.client('s3') | |
| bucket = os.environ['BUCKET'] | |
| key = os.environ['KEY'] | |
| s3.download_file(bucket, key, '/tmp/model.pkl') | |
| # LOAD MODEL | |
| model = joblib.load('/tmp/model.pkl') | |
| def handler(event, context): | |
| # TRANSFORM DATA | |
| data = pd.DataFrame(event, index=[0]) | |
| # PREDICT | |
| prediction = float(model.predict(data)) | |
| return { | |
| 'rf': round(prediction, 2) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment