🧠 AI with Python – 📊 Building a Simple ML Dashboard (Streamlit Metrics)
Posted on: June 25, 2026
Description:
Training and deploying a machine learning model is only part of the journey. Once a model is in production, teams need visibility into how it is performing over time.
Questions such as:
- Is accuracy declining?
- Are predictions increasing?
- Is model confidence changing?
- Do we need retraining?
cannot be answered by the model alone.
This is where ML dashboards become valuable.
In this project, we build a simple machine learning monitoring dashboard using Streamlit, one of the most popular frameworks for rapidly creating data applications in Python.
Why ML Dashboards Matter
Imagine a model deployed in production six months ago. The model continues generating predictions every day. Without monitoring, the team has no easy way to know:
- whether performance is stable
- whether prediction volume is changing
- whether confidence scores are decreasing
- whether concept drift is occurring
A dashboard provides a centralised view of model health.
What Is an ML Dashboard?
An ML dashboard is a visual interface that displays important model metrics in real time or near real time.
Typical information includes:
- Accuracy
- Precision
- Recall
- F1 Score
- Prediction Volume
- Confidence Scores
- Drift Indicators
These metrics help teams understand how models behave after deployment.
Why Streamlit?
Streamlit makes it possible to create dashboards using pure Python.
Instead of building:
- frontend applications
- APIs
- JavaScript components
developers can create interactive dashboards with only a few lines of code.
Example:
st.title("ML Model Monitoring Dashboard")
A complete web application is generated automatically.
Creating Monitoring Data
For this example, we simulate model monitoring metrics.
monitoring_data = pd.DataFrame(...)
The dataset contains:
- daily accuracy
- precision
- recall
- F1 score
- prediction volume
- confidence scores
These values mimic production monitoring information.
Displaying Key Metrics
The first section of the dashboard highlights current model performance.
col1.metric(
"Accuracy",
latest["accuracy"]
)
Streamlit’s metric component creates compact KPI cards.
Typical dashboards display:
- current accuracy
- current precision
- current recall
- current F1 score
at the top of the page.
Visualising Accuracy Trends
Metrics become more meaningful when viewed over time.
ax.plot(
monitoring_data["date"],
monitoring_data["accuracy"]
)
Trend charts help answer questions such as:
- Is accuracy stable?
- Is performance degrading?
- Did accuracy suddenly change?
Visualisation often reveals issues that raw numbers cannot.
Monitoring Prediction Volume
Prediction volume is another useful signal.
ax.plot(
monitoring_data["prediction_volume"]
)
Unexpected changes in volume may indicate:
- traffic spikes
- system failures
- upstream pipeline issues
Monitoring usage patterns helps teams identify operational problems.
Adding Alerts
Production dashboards often include alerting logic.
if latest["accuracy"] < 0.90:
st.warning(...)
Alerts allow teams to react quickly when performance drops below acceptable thresholds.
Examples include:
- declining accuracy
- increasing latency
- confidence degradation
- drift detection events
Displaying Raw Data
Dashboards often include underlying monitoring records.
st.dataframe(
monitoring_data
)
This provides transparency and supports deeper investigation. Users can inspect the actual values behind visualisations.
What Real ML Dashboards Monitor
Production systems often track much more than accuracy. Common metrics include:
Model Metrics
- accuracy
- precision
- recall
- F1 score
- ROC-AUC
Operational Metrics
- prediction volume
- latency
- throughput
- error rates
Data Metrics
- feature drift
- concept drift
- missing value rates
- distribution changes
Modern MLOps platforms combine all of these into a unified dashboard.
Where ML Dashboards Are Used
Monitoring dashboards are common in:
- fraud detection systems
- recommendation engines
- healthcare ML platforms
- financial risk systems
- customer analytics products
Any production ML system benefits from visibility into performance and usage.
Advantages of Streamlit Dashboards
Streamlit offers several benefits:
- rapid development
- minimal frontend knowledge required
- interactive visualisations
- Python-native workflow
- easy deployment
This makes it an excellent choice for ML engineers and data scientists.
Key Takeaways
- ML dashboards provide visibility into production model health.
- Streamlit allows dashboards to be built using only Python.
- Metrics such as accuracy, precision, recall, and F1-score are commonly monitored.
- Trend visualisations help identify degradation and anomalies.
- Dashboards are a foundational component of modern MLOps practices.
Conclusion
Deploying a machine learning model without monitoring is like driving a car without a dashboard. Teams need visibility into performance, usage patterns, and potential issues to keep models reliable over time. Streamlit provides a fast and practical way to build monitoring dashboards that help organisations understand and maintain production ML systems.
Code Snippet:
# 📦 Import Required Libraries
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# =========================================================
# 📝 Create Sample Monitoring Data
# =========================================================
monitoring_data = pd.DataFrame({
"date": pd.date_range(
start="2025-01-01",
periods=10,
freq="D"
),
"accuracy": [
0.96, 0.95, 0.95, 0.94, 0.93,
0.92, 0.91, 0.90, 0.89, 0.88
],
"precision": [
0.95, 0.94, 0.94, 0.93, 0.92,
0.91, 0.90, 0.89, 0.88, 0.87
],
"recall": [
0.94, 0.94, 0.93, 0.92, 0.91,
0.90, 0.89, 0.88, 0.87, 0.86
],
"f1_score": [
0.945, 0.94, 0.935, 0.925, 0.915,
0.905, 0.895, 0.885, 0.875, 0.865
],
"prediction_volume": [
500, 520, 510, 540, 560,
580, 600, 610, 630, 650
],
"avg_confidence": [
0.94, 0.94, 0.93, 0.92, 0.91,
0.90, 0.89, 0.88, 0.87, 0.86
]
})
# =========================================================
# 🖥️ Streamlit Dashboard Title
# =========================================================
st.title("ML Model Monitoring Dashboard")
st.write(
"Simple dashboard to track model performance metrics over time."
)
# =========================================================
# 📊 Display Latest Metrics
# =========================================================
latest = monitoring_data.iloc[-1]
col1, col2, col3, col4 = st.columns(4)
col1.metric(
"Accuracy",
round(latest["accuracy"], 3)
)
col2.metric(
"Precision",
round(latest["precision"], 3)
)
col3.metric(
"Recall",
round(latest["recall"], 3)
)
col4.metric(
"F1 Score",
round(latest["f1_score"], 3)
)
# =========================================================
# 📈 Accuracy Trend
# =========================================================
st.subheader("Accuracy Trend")
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(
monitoring_data["date"],
monitoring_data["accuracy"],
marker="o"
)
ax.set_title("Model Accuracy Over Time")
ax.set_xlabel("Date")
ax.set_ylabel("Accuracy")
ax.grid(True)
st.pyplot(fig)
# =========================================================
# 📈 Classification Metrics Trend
# =========================================================
st.subheader("Classification Metrics Trend")
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(
monitoring_data["date"],
monitoring_data["precision"],
marker="o",
label="Precision"
)
ax.plot(
monitoring_data["date"],
monitoring_data["recall"],
marker="o",
label="Recall"
)
ax.plot(
monitoring_data["date"],
monitoring_data["f1_score"],
marker="o",
label="F1 Score"
)
ax.set_title("Precision, Recall, and F1-score Over Time")
ax.set_xlabel("Date")
ax.set_ylabel("Score")
ax.legend()
ax.grid(True)
st.pyplot(fig)
# =========================================================
# 📈 Prediction Volume Trend
# =========================================================
st.subheader("Prediction Volume Trend")
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(
monitoring_data["date"],
monitoring_data["prediction_volume"],
marker="o"
)
ax.set_title("Prediction Volume Over Time")
ax.set_xlabel("Date")
ax.set_ylabel("Prediction Count")
ax.grid(True)
st.pyplot(fig)
# =========================================================
# 📈 Average Confidence Trend
# =========================================================
st.subheader("Average Confidence Trend")
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(
monitoring_data["date"],
monitoring_data["avg_confidence"],
marker="o"
)
ax.set_title("Average Prediction Confidence Over Time")
ax.set_xlabel("Date")
ax.set_ylabel("Average Confidence")
ax.grid(True)
st.pyplot(fig)
# =========================================================
# 🚨 Simple Monitoring Alerts
# =========================================================
st.subheader("Monitoring Alerts")
if latest["accuracy"] < 0.90:
st.warning("⚠️ Accuracy has dropped below threshold.")
else:
st.success("✅ Accuracy is within healthy range.")
if latest["avg_confidence"] < 0.87:
st.warning("⚠️ Average confidence is decreasing.")
else:
st.success("✅ Average confidence is within healthy range.")
# =========================================================
# 📋 Display Raw Monitoring Data
# =========================================================
st.subheader("Monitoring Data")
st.dataframe(monitoring_data)
# =========================================================
# ▶️ Run Command
# =========================================================
st.info(
"Run this dashboard using: streamlit run ml_dashboard.py"
)
No comments yet. Be the first to comment!