This post describes developing a web application for a machine learning model and deploying it so that it can be accessed by anyone. The web application is available at:
The process of deployment consists of transferring all flask application files from a local computer to the web server. Once completed the web application can be visited by anyone through a public URL. The cloud platform used is Heroku because it supports Python web applications built with various programming languages including applications built with Python flask. Heroku makes things easier by handling administrative tasks by itself so one can focus on the programming part. Another good thing is that web applications is hosted for free. As the traffic increases, one may want to sign up for one of the better plans so that the web application performs well in high traffic.
The steps involved are as follows:
Creating a simple model that can be deployed to the web, where users can input variables to get predictions
For this post, the model is a simple linear regression model based on the paper “Assessment of Irish Mortgage Arrears at County Level using Machine Learning Techniques and Open Data”. The code and the paper is available for download here. The model is a simple linear regression and predicts the mortgage arrears for the year for county of Ireland.
Building the components needed by Flask microframework to create a web app
Deploying the final web app using the Heroku platform.
- Using the git tool to send local files to the online webserver or cloud. So, the first thing to do is to download git from https://git-scm.com/downloads and install it.
- Sign up for a free account on Heroku: com.
- Download and install Heroku Toolbelt from https://toolbelt.heroku.com/.
Heroku Toolbelt is a package that allows you to interact with the Heroku cloud through computer command line and it needs git to do that. You already installed git in step 1.
- Make a git repository for the app using git init (use Git CMD for windows)
- Start interacting with Heroku account by typing : heroku login
Enter heroku account credentials when asked about them.
- Create a custom Heroku app: heroku create arrear-model
- Create the required Heroku files :
- Create an empty file named Procfile in current folder. Then enter this line inside the empty file: web: gunicorn app:app . The file shouldn’t have any extension, so make sure the file name is not getting a .txt extension.
- Create a requirements.txt file to tell Heroku which packages to install for web app by typing:
- Add all local files to the online repository by typing:
git add .
Make sure to include the dot after add. The dot means adding the entire directory to the repository.
- Commit your files with:
git commit –m “First commit”
- Set the remote destination for pushing from git to Heroku
heroku git:remote -a arrear-model
Makes it easier to push local web app to Heroku, using git.
- Push application to Heroku:
git push heroku master
- Make sure at least one instance of the app is running with:
heroku ps:scale web=1
If everything goes as expected, the app is now live. To check out the deployed app either use heroku open command or just go to