Original Source Here
How to Build an Online Machine Learning App with Python
Offering simplified and scalable machine learning as a service
Machine learning is rapidly becoming as ubiquitous as data itself. Quite literally wherever there is an abundance of data, machine learning is somehow intertwined. And for good reason too. After all, what utility would data have if we were not able to use it to predict something about the future? Luckily there is a plethora of toolkits and frameworks that have made it rather simple to deploy ML in Python. Specifically, Sklearn has done a terrific job at making ML accessible to developers.
Even still, there are many technical and STEM-associated individuals that would have plenty of use for ML but who lack the necessary coding skills to see it through. This specific audience would require a solely visual tool with a friendly user interface that would allow them to replicate exactly what others would do with code.
These days tech is dominated by the ‘as-a-service’ paradigm that seeks to offer literally anything as a service, including but not limited to software, databases, CAD, and so forth. There’s no reason to believe that machine learning is somehow exempt from this notion. As you have probably guessed by now, there is indeed the term MLaaS or in other words, machine learning as a service.
While there are quite a few MLaaS platforms out there, most of them appear to be priced quite heftily, with some setting you back upwards of $300 a month. Well truth be told, it doesn’t have to be that way. There is in fact a way for you to render your own simplified MLaaS platform as an online web application. And in this tutorial, I will show you exactly how to do that.
But before we proceed any further, please take a look at the final ML app:
You can also test the ML App at the following link:
To implement our own version of MLaaS, we will be using the Sklearn library in Python. The novelty of this package is that it simplifies the complexity of training, and testing a variety of ML classifiers including but not limited to logistic regression, naive Bayes, support vector machine, decision tree, and K nearest neighbors.
To render our ML platform as a web app, we will be using Streamlit. Streamlit is a pure Python web framework that has all but closed the app development gap for Python programmers. It is a robust and scalable API with an exceptionally shallow learning curve, that has reduced development time from weeks to minutes.
To plot and visualize your confusion matrix, ROC curve, and perhaps other data, we will be using Plotly — my favorite library when it comes to visualizing interactive charts and visuals in a web application.
Pandas gives you the ability to manipulate, mutate, transform and visualize data in frames, all with a couple of lines of code. In this application, we will use Pandas to read/write our data from/into csv files and to manipulate our data frames based on selected parameters.
Please proceed by firing up Anaconda or any Python IDE of your choice and installing Sklearn as shown below:
pip install sklearn
Subsequently, import all of the required packages:
import streamlit as st
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
In our ML app, we will create a logistic regression classifier, where we first upload a training dataset that we will use to train our model with. We will gauge the performance of our hyperparameters by visualizing the confusion matrix and ROC curve. And finally, when we are happy, we will upload an unlabeled test dataset to apply our ML model.
Dataset upload widget
First, we will create a file upload function as shown below:
Then, we will create multiple widgets to select our feature columns, label column, hyperparameters, and advanced parameters as shown below:
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot