Deployment of Web App + ML Model + APIs — Tutorial

We will create an app to predict the probability of a Data Scientist earn more than USD 100k per year.André SionekBlockedUnblockFollowFollowingDec 4What is the point of creating a ML model if you don’t put it into production?.You can think of this tutorial as the first step into becoming a data science unicorn.What are we doing here?We will deploy a Logistic Regression model in AWS Lambda and then create API endpoints with API Gateway..To deploy it we have basically two options:Export the model as as serialized object, load into AWS lambda and start making predictions.Parametrize the model and load all coefficients and intercept manually to Lambda.I’m choosing the second option because I want the model to be transparent to anyone..A serialized model wouldn’t let us see that in detail.You’ll find instructions on how to deploy a serialized model to AWS Lambda on this Towards Data Science post, by Ben Weber.Parametrization: What the hell is that?A Logistic Regression model can be written like this:log-odds = b0 + b1x1 + b2x2 + ….We just created a scalable service that runs our model given an input..Now we build a web app that sends a request to our service and expects the score as answer.The full project has more functions, check it out here:andresionek91/kaggle-top20-predictorPredicts if a Data Scientist earns more than USD100k per year – andresionek91/kaggle-top20-predictorgithub.comThird: The Flask AppCreate a project with the following folder structure (you can just clone it from my github).There are two HTML pages (index.html and score.html) stored inside templates folder..Make sure that the code is committed and pushed to master.Open the terminal and run pip install awsebcli to install the Beanstalk command line interfaceThen cd to you project folder and run eb initAfter running that you can run eb create to create your applicationFinally eb open will open your app urlDo do additional deploys and updates:First commit/push the codeThen run eb deployThe full Flask project is available here:andresionek91/data-scientist-valueFlask app to calculate compensation of a data scientist – andresionek91/data-scientist-valuegithub.comThis was a tutorial to deploying a ML model as a service, creating an API, and finally a building web application using Flask that make requests to our model’s API.. More details

Leave a Reply