The Best Data Science Framework You’ve Never Heard Of
By: Aden Haussmann
Tags: Machine Learning, Data Science, Streamlit, Web App Development, Python

The Best Data Science Framework You’ve Never Heard Of

A web app built in Streamlit (all screenshots by Author)

If you’ve ever wanted to take the machine learning models or data visualisations you’ve created and turn them into web apps for other people to view and interact with, at some point you probably felt a little lost.

You might be an excellent data scientist, very familiar with the tools you need to wrangle data, extract insights, build visualisations and create models, but putting those into production takes more. As Adrien Treuille, co-founder and CEO of Streamlit, put it, “Machine learning engineers are actually app-makers.”

Streamlit is a relatively young framework that offers a breath of fresh air and a way to create beautiful data-driven apps really quickly and easily. So what problem does it solve, who is it meant for, and should you use it?

The Problem

The machine learning/data science pipeline looks something like this:

Data > Training > Model > Production

Throughout the process, it is often the case that many bespoke solutions have to be engineered, from prototypes to demos to dashboards and so on… Whether you’re building an enterprise solution that will be used widely by salespeople within your company, or just working on a personal project, this requires software engineering.

An Example

Adrien Treuille recalls when he worked at Zoox, and about 80 Machine Learning Engineers were building self-driving car systems. They were doing everything: planning, vision, pedestrian detection, the whole stack.

He makes the example of a type of tool the engineers might need to build: an app to run two self-driving systems at the same time and compare them. This would probably start out as a project for a single engineer, written in a Jupyter Notebook, copied and pasted into a Python script, pushed to GitHub and built out with a framework like Flask.

But suppose the app becomes an important part of the team’s workflow and suddenly more engineers need to use it and features need to be added, but it wasn't designed to be a well-polished, extendable piece of software. This is what Adrian calls “the unmaintainability trap”.

At this stage, the Machine Learning Engineers would call in an internal team who were essentially experts in building web apps. This team would collect requirements of the system, wireframe it and develop it in React or Vue with JavaScript, Python, CSS, HTML etc., ultimately creating a stunning and well-designed app.

But then they’d need to move on to a different project, support a different team, and the app would be in “the frozen zone” until they could return to it. Even if you’re working on a solo project and not in a large company, this dependency on software engineering to deploy your app can make life very difficult.

The Solution

Streamlit is an app framework that asks the question:

What if we could make building tools as easy as writing Python scripts?

The goal is to shift the web app-building philosophy from starting with a layout and developing an event model, to a Python script-esque top to bottom execution, data flow transformation style that data scientists should be very used to.

In Adrien’s own words, a Streamlit app is “basically a data script that has been slightly annotated to make it an interactive app”.

I can tell you from personal experience that Streamlit delivers on this promise. You can even take a Python script that already exists and turn it into a web app simply by adding a few Streamlit calls, all in a single file.

Is it Really That Simple?

Yes! Check this out:

Want to create a slider to choose a value to input into a model?

val = st.slider()

# Use val

You just declare a variable and set it equal to Streamlit’s slider widget, then adjust some parameters to your liking. This will display the slider in your app and set the value of val to whatever the user slides to. It’s just as easy to create buttons, checkboxes, radios, select boxes, multi-select boxes and more.