Develop and sell a Machine Learning app — from start to end tutorial
By: Daniel Deutsch
Tags: AWS, Machine Learning, Programming, Getting Started, Data Science

COVID-19 prediction end-to-end app

After developing and selling a Python API, I now want to expand the idea with a machine learning solution. So I decided to quickly write a COVID-19 prediction algorithm, deploy it, and make it sellable. If you want to see how I did it, check out the post for a step by step tutorial.

Table of Contents

About this article

In this article, I take the ideas from my previous article “How to sell a Python API from start to end” further and build a machine learning application. If the steps described here are too rough consider reading my previous article first.

There are a number of new and more complicated issues to cover in this project:

Machine Learning content. The application takes basic steps of building a Machine Learning model. This covers the preparation, but also the prediction. In time evaluation (not in time training) of the prediction. This means that the dataset is freshly fetched and the prediction is performed on the latest data. Deployment. Deploying a Machine Learning app has various challenges. In this article, we met and solved the issue of outsourcing the trained model on AWS. It is not only an API but also has a minor frontend.

It paints a picture for developing a Python API from start to finish and provides help in more difficult areas like the setup with AWS Lambda.

There were various difficulties, which allowed me to learn more about the deployment and building process. It is also a great way to build side projects and maybe even make some money.

As the Table of content shows, it consists of 4 major parts, namely:

Setting up the environment Creating a problem solution with Python Setting up AWS Setting up Rapidapi

You will find all my code open on Github:

You will find the end result here on Rapidapi:

Disclaimer

I am not associated with any of the services I use in this article.

I do not consider myself an expert. If you have the feeling that I am missing important steps or neglected something, consider pointing it out in the comment section or get in touch with me. Also, always make sure to monitor your AWS costs to not pay for things you do not know about.

I am always happy for constructive input and how to improve.

There are numerous things to improve and build upon. For example, the machine learning part has a very low effort. The preparation was very rough and many steps are missing. From my professional work, I am aware of this fact. However, I cannot cover every detail in one article. Nevertheless, I am curious to hear your suggestions on improvement in the comments. :)

If you need more information on certain parts, feel free to point it out in the comments.

Regarding the term “tutorial”

I consider this as a step by step tutorial. However, as I am already too long working as a developer, I assume some knowledge of certain tools. This makes the tutorial probably an intermediate/advanced app.

I assume knowledge of:

Python

Git

Jupyter Notebook

Terminal/Shell/Unix commands

Stack used

We will use

Github (Code hosting),

Anaconda (Dependency and environment management),

Docker (for possible further usage in microservices)

Jupyter Notebook (code development and documentation),

Python (programming language),

AWS, especially AWS Lambda and S3(for deployment),

Rapidapi (market to sell)

1. Create project formalities

It’s always the same but necessary. I do it along with these steps:

Create a local folder mkdir NAME Create a new repository on Github with NAME Create conda environment conda create --name NAME python=3.7 Activate conda environment conda activate PATH_TO_ENVIRONMENT Create git repo git init Connect to Github repo. Add Readme file, commit it and

git remote add origin URL_TO_GIT_REPO

git push -u origin master

2. Develop a solution for a problem

As we will develop a Machine Learning solution, a Jupyter Notebook will be very useful.

Install packages and track Jupyter files properly

Install jupyter notebook and jupytext:

pip install notebook jupytext

Register new environment in jupyter ipython kernel install --name NAME--user

Set a hook in .git/hooks/pre-commit for tracking the notebook changes in git properly:

touch .git/hooks/pre-commit

code .git/hooks/pre-commit

copy this in the file

#!/bin/sh

# For every ipynb file in the git index, add a Python representation

jupytext --from ipynb --to py:light --pre-commit

afterward for making the hook executable (on mac)

chmod +x .git/hooks/pre-commit

Develop a solution to a problem

The goal

As currently, the world is in a pandemic I thought I use one of the multiple datasets for Covid-19 cases. Given the structure of the dataset, we want to predict the new cases of infections per day for a country.

pip install -r requirements.txt

This will install all packages we need. Have a look in the /development/predict_covid.ipynb notebook to see what libraries are used.

Most important are the libraries

pandas for transforming the dataset and

sklearn for machine learning

For the following subheadings please check out the Jupyter notebook for more details: