Build A Beautiful Machine Learning Web App With Streamlit And Scikit-learn
In this tutorial we build an interactive machine learning app with Streamlit and Scikit-learn to explore different datasets and classifier.
In this tutorial we build an interactive machine learning app with Streamlit and Scikit-learn to explore different datasets and classifier. This tutorial should demonstrate how easy interactive web applications can be build with Streamlit. Streamlit lets you create beautiful apps for your machine learning projects with simple Python scripts. See official Streamlit website for more info. As a bonus, you will also learn how we can implement Machine Learning classification pipelines using Scikit-learn.
You can find the code and a Preview gif on GitHub.
Just install with pip (I recommend to use a virtual environment)
pip install streamlit
pip install scikit-learn
pip install matplotlib
Run the App¶
After installation I recommend to have a look at the official example app by running
streamlit run file_name.py
Start Implementing and Add Widgets¶
With streamlit we can create beautiful UI widgets with just a few lines of code. Here are some example widgets. Have a look at the official docs to see all possibilities.
import streamlit as st
# use markdown syntax
# Explore different classifier and datasets
Which one is the best?
# selectbox (move it to the sidebar with .sidebar)
dataset_name = st.sidebar.selectbox(
('Iris', 'Breast Cancer', 'Wine')
# widgets can be assigned to variables,
# which obtain the value of the selection
K = st.sidebar.slider('K', 1, 15)
fig = plt.figure()
Data Flow and Caching¶
Streamlit reruns your Python script from top to bottom whenever the user interacts with the widgets. However, to stay fast and performant, streamlit has integrated some intelligent caching mechanisms. Find out more here.
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions: Link*
PySaaS: The Pure Python SaaS Starter Kit
🚀 Build a software business faster with pure Python: Link*