Created
July 21, 2017 10:26
-
-
Save alexcasalboni/9f1455e383bb41ee748b7920a43ae8b6 to your computer and use it in GitHub Desktop.
AmazonML Lab updated code
This file contains 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 boto3 | |
from boto3.session import Session | |
session = Session(aws_access_key_id='AWS_ACCESS_KEY_ID', aws_secret_access_key='AWS_SECRET_ACCESS_KEY') | |
machinelearning = session.client('machinelearning', region_name='us-east-1') | |
labels = {'1': 'walking', '2': 'walking upstairs', '3': 'walking downstairs', '4': 'sitting', '5': 'standing', '6': 'laying'} | |
# fill your model ID and Endpoint here! | |
model_id = 'MODEL_ID' | |
prediction_endpoint = 'MODEL_ENDPOINT' | |
def get_record(filename='record.csv'): | |
record = {} | |
with open(filename) as f: | |
for index, val in enumerate(f.readline().split(',')): | |
record['Var%03d' % (index + 1)] = val | |
return record | |
try: | |
response = machinelearning.predict( | |
MLModelId=model_id, | |
Record=get_record(), | |
PredictEndpoint=prediction_endpoint, | |
) | |
except Exception as e: | |
print(e) | |
else: | |
label = response['Prediction']['predictedLabel'] | |
print("You are currently %s." % labels[label]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment