Deploying an ML Model to Production using GCP and MLFlow

Byron Allen
Jun 16 · 7 min read
Source: lalo Hernandez

Model Performance

Confusion matrix to show the model is converging well

Deployment to GCP’s Cloud ML Engine

from googleapiclient import discoverydef Predict(tweet, project_id, model_name, version_name):

service = discovery.build(‘ml’, ‘v1’)
name = ‘projects/{}/models/{}’.format(project_id, model_name)
if version_name is not None:
name += ‘/versions/{}’.format(version_name)
response = service.projects().predict(
name=name
, body={‘instances’: tweet}
).execute()
if ‘error’ in response:
output = response[‘error’]
else:
output = response[‘predictions’]
return output

Post-deployment Validation

{“instances”: [“Today, it was my great honor to address the the National     Association of REALTORS!”, “With all of the Fake and Made Up News out there, Iran can have no idea what is actually going on!”, “It now seems the General Flynn was under investigation long before was common knowledge. It would have been impossible for me to know this but, if that was the case, and with me being one of two people who would become president, why was I not told so that I could make a change?”, “The Fake News Media is hurting our Country with its fraudulent and highly inaccurate coverage of Iran. It is scattershot, poorly sourced (made up), and DANGEROUS. At least Iran doesn’t know what to think, which at this point may very well be a good thing!”, “Will Jerry Nadler ever look into the fact that Crooked Hillary deleted and acid washed 33,000 emails AFTER getting a most powerful demand notice for them from Congress?”, “My Campaign for President was conclusively spied on. Nothing like this has ever happened in American Politics. A really bad situation. TREASON means long jail sentences, and this was TREASON!”, “New Fox Poll: 58% of people say that the FBI broke the law in investigating Donald J. Trump. @foxandfriends”, “MAKE AMERICA GREAT AGAIN!”, “DRAIN THE SWAMP!”, ““What happened is that Donald Trump won. Down goes Comey.” @foxandfriends”]}
{‘Commercial’: 3, ‘RightTroll’: 4, ‘HashtagGamer’: 5, ‘LeftTroll’: 2, ‘NewsFeed’: 0, ‘Verified’: 1}
https://knowyourmeme.com/photos/1262065-donald-trump

Conclusion


WeAreServian

The Cloud and Data Professionals

Byron Allen

Written by

Texan transplant to Australia turned Australian transplant to the UK. Evangelist of continuous experimentation in ML. Senior Consultant at Servian.

WeAreServian

The Cloud and Data Professionals