Classification Demo
Source: 14-Streamlit/classification.py
Start here — no coding background needed
What you will learn
Example ML demo — predict categories from data.
In simple words
Advanced demo: train a model, show results in Streamlit — try locally when ready.
Quick dashboards and demos — great for showing data without HTML/CSS.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
Reference script from the bootcamp repo. Read the code below; run a simplified version in the playground when marked runnable.
import streamlit as st
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
@st.cache_data
def load_data():
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['species'] = iris.target
return df, iris.target_names
df,target_names=load_data()
model=RandomForestClassifier()
model.fit(df.iloc[:,:-1],df['species'])
st.sidebar.title("Input Features")
sepal_length = st.sidebar.slider("Sepal length", float(df['sepal length (cm)'].min()), float(df['sepal length (cm)'].max()))
sepal_width = st.sidebar.slider("Sepal width", float(df['sepal width (cm)'].min()), float(df['sepal width (cm)'].max()))
petal_length = st.sidebar.slider("Petal length", float(df['petal length (cm)'].min()), float(df['petal length (cm)'].max()))
petal_width = st.sidebar.slider("Petal width", float(df['petal width (cm)'].min()), float(df['petal width (cm)'].max()))
input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
## PRediction
prediction = model.predict(input_data)
predicted_species = target_names[prediction[0]]
st.write("Prediction")
st.write(f"The predicted species is: {predicted_species}")
Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
You learned "Classification Demo". Use print() to show: Done: Classification Demo
Hint: Use one print() with the exact text.