How To Deploy Machine Learning Models to the Web
Photo by Tim Mossholder on Unsplash
By Travis Wolf
The goal of completing a machine learning model lifecycle is to deploy and maintain a working pipeline of data. As more companies look to implement ML models to optimize data-driven functions, being able to deliver and maintain these models will require a web framework that can provide a user experience as well as adapt to data as it changes.
As a data scientist, it is expected to take on many different responsibilities of the ML model’s lifecycle. However, most are not highly experienced with front and back end development of web applications. Over time this might change as more data scientists become experts on deployment, but luckily some web frameworks in recent years have been developed to streamline the deployment process by offering simple solutions that don’t require a lot of prior knowledge of web development.
Depending on the scenario, the following five web frameworks can accomplish development of a data-driven web application.
Examples/ Use Cases of ML in Web-Based Applications
- Optimization of transportation routes for logistics companies.
- NLP to enhance customer interactions through use of autocomplete and suggested text.
- Predictive modeling to maximize ROI of marketing spending.
- Anomaly detection and security to monitor fraudulent transactions on eCommerce websites.
- Recommendation engines to display content to users.
- Voice-Based Search Functions; add an AI function that can recognize speech to perform search functions, similar to Siri, Google Assistant.
Dash Enterprise by plotly
Dash Enterprises offers a solution for data science teams looking to bypass full-stack development of analytic web applications, potentially saving money in the process of hiring developers. Dash aims at providing an end-to-end deployment platform to be used by a single data scientist, allowing them to develop analytics in a relatively low code environment.
Using this web framework is advantageous because it allows data scientists to be directly involved with the communication and subject matter with the business decision makers and subject matter experts, ultimately resulting in optimization of AI and ML for the business problem.
Writing a Dash app is also simple, aiming to provide a user-interactive web-based application all within pure python. Dash is a powerful framework because it is written on top of established web frameworks like Plotly.js, Flask, and React.js. Once the app has been developed and deployed to a server, users can access them through any web browser, even mobile.
Streamlit
Streamlit is an open-source web framework designed to easily and quickly build a web application, with no front-end experience required. This is a simple solution for data scientists looking to report their findings with a working demonstration of their model’s performance with ongoing data integration.
The process of building the web application is very straightforward; write the python code in a script, and the Streamlit API will read and interpret the code onto a web page. Deploying the app is also painless, with the ability to deploy the application directly from a Github repository.
Streamlit’s ease of use, and speed of production, make it a great tool for a data scientist in 2021 to add to their ML pipeline. However, Streamlit does not have the builtin capacity to scale at large. This web framework would be best suited for personal projects or to be shared within a data science team, not for high-level prototypes or production.
Flask
Flask, like the last two web frameworks, is designed to quickly build a web application written in python. However, Flask was not initially created to accommodate data scientists, but is a popular choice among the data science community.
Flask is considered a microframework, which refers to it being lightweight, practical, and self-containing. It is designed to develop a web application with no additional tools or libraries needed. It is based on the powerful template engine Jinja and the WSGI toolkit, making it an effective solution for building a web application from the ground up, offering more customization than Streamlit or Dash.
For a data scientist looking to integrate their machine learning model in a fully functional prototype, Flask is the way to do it. Flask is popular to use for data science applications because of its powerful and generic solutions for developing a web application with a python library. It’s a great web framework that is simple enough to get started quickly, yet flexible enough to accommodate large scale productions that have complex data sources.
AWS Amplify
Not surprisingly, AWS does offer a solution to building a cloud-powered mobile and web apps. After developing the front and back end of the web application, a REST API call can be made to a custom model in AWS Sagemaker to retrieve output from a model. Although Data Science is a highly interdisciplinary role, not many are equipped with the knowledge of full-stack web development.
However, as a web developer with absolutely zero machine learning experience, implementing an AI or ML service through AWS can be a clever option to implement object recognition or NLP into a web application.
Drawbacks to this are if you have a very specific model that was developed for a specific use case, this is not the right framework to be building a web application on. This framework would be better suited for AI/ML services that are actually provided by AWS, such as object detection or translation, and will work well within the AWS ecosystem.
Django
The Django web framework is the most advanced way of deploying a machine learning model, and is capable of building large and complex scale web applications. Websites like Instagram, Washington Post, and Pinterest all use Django to weave machine learning models into their application. Django is able to utilize resources based on the number of users, and is best used for REST API development.
Django is a full-stack web development platform. The advantage of choosing to use Django for your data application is that it has a high availability of add-ons and features. If your goal is to develop a fully functional web application with many moving parts that require requests from databases, then this would best suit your needs.
However, Django is not best suited for data scientists in general because it does require a lot of overhead of knowledge of web development. Whereas Flask adopts a minimalist’s approach and is preferred for functional applications that require a straightforward process of requesting inputs, making predictions, and responding with the results.
Conclusion
A model spent idle in a Jupyter notebook never to be applied on a real world problem would be like building a car in a garage, but never learning how to drive it. As machine learning and AI become more integrated with optimizing businesses needs, there will be a higher demand for a skill set of deploying and continuous integration of models. With this increase in demand, it would be valuable for data science teams to shift focus onto optimizing the deployment “learning to drive” step of their model’s lifecycle.
Building a web application is a great way for end users to actually experience the findings that the data science team had discovered in a production environment, and also build upon the dataset for models to be retrained and evaluated. With the web frameworks mentioned in this article, a data science team will be able to effectively deploy and maintain a web application depending on the use case and scale of operation.
Thanks for reading! If you want to read more about data consulting, big data, and data science, then click below.
Developing A Data Analytics Strategy For Small Businesses And Start-ups
3 Ways To Improve Your Data Science Teams Efficiency
4 SQL Tips For Data Scientists
How To Improve Your Data-Driven Strategy
What Is A Data Warehouse And Why Use It
Mistakes That Are Ruining Your Data-Driven Strategy
5 Great Libraries To Manage Big Data With Python