Notebook – Metric Dashboard#
Where Your Metrics Learn to Dance 💃 (and Impress the CFO)
“Spreadsheets make people yawn. Dashboards make them clap.” 👏
Welcome to the Metric Dashboard Lab — your mission: Combine your model performance metrics, visuals, and business storytelling into one interactive dashboard that would make even your manager say,
“Wait, you built this in Python?” 🤯
🎬 Business Hook: The Boardroom Moment#
You’ve trained a sales forecast model. You have metrics. You have visuals. But in your meeting, someone asks:
“Can you show how this changes by product line and region?”
You gulp. Then smile. Because you built this lab. 😎
🧩 Your Objectives#
By the end of this lab, you’ll be able to: ✅ Build a dashboard-like notebook to compare models ✅ Display interactive visuals using Plotly ✅ Present key metrics with a business narrative ✅ Let users filter and explore model results
⚙️ Step 1. Load the Sample Data#
import pandas as pd
# Example performance data
data = {
'Model': ['Linear Regression', 'Random Forest', 'XGBoost', 'Prophet'],
'MAE': [250, 180, 160, 200],
'RMSE': [300, 220, 190, 240],
'R2': [0.82, 0.91, 0.93, 0.88],
'Business Unit': ['Retail', 'Retail', 'Wholesale', 'Wholesale']
}
df = pd.DataFrame(data)
df
🧠 Pro Tip: Replace this with your own metrics! Try loading data from your previous chapters — regression, classification, etc.
🧮 Step 2. Compute Derived KPIs#
You can turn your metrics into business-friendly indicators.
df['Improvement_vs_Baseline'] = ((df['R2'] - df['R2'].min()) / df['R2'].min()) * 100
df['Error_Reduction_%'] = ((df['RMSE'].max() - df['RMSE']) / df['RMSE'].max()) * 100
df[['Model', 'Improvement_vs_Baseline', 'Error_Reduction_%']]
💬 “Because no one gets excited about RMSE = 190, but they do get excited about ‘error reduced by 35%.’” 📉
📈 Step 3. Visualize the Metrics (Plotly Style)#
import plotly.express as px
fig = px.bar(df, x='Model', y='R2', color='Business Unit', text='R2',
title='📊 Model Performance by R²',
labels={'R2': 'R² Score'})
fig.update_traces(texttemplate='%{text:.2f}', textposition='outside')
fig.update_layout(yaxis_range=[0, 1])
fig.show()
🎨 Plotly Tip: The fewer colors, the more “executive-friendly” your chart looks.
💼 Step 4. Create KPI Cards#
This is the “wow” part of your dashboard — mini metric boxes that show results at a glance.
from IPython.display import display, Markdown
for _, row in df.iterrows():
display(Markdown(f"""
### 🚀 {row['Model']}
- **R²:** {row['R2']:.2f}
- **RMSE:** {row['RMSE']}
- **MAE:** {row['MAE']}
- **Error Reduction:** {row['Error_Reduction_%']:.1f}%
"""))
💬 “Congratulations — you just built mini KPI cards like a pro dashboard designer.”
🧠 Step 5. Add Interactivity (Optional but Awesome)#
Use widgets to filter your dashboard — because executives love clicking buttons.
import ipywidgets as widgets
from IPython.display import clear_output
model_dropdown = widgets.Dropdown(options=df['Model'].unique(), description='Choose Model:')
output = widgets.Output()
def show_model_metrics(change):
with output:
clear_output()
model = change['new']
row = df[df['Model'] == model].iloc[0]
display(Markdown(f"""
## 📊 {model} Metrics
- **R²:** {row['R2']:.2f}
- **RMSE:** {row['RMSE']}
- **MAE:** {row['MAE']}
- **Error Reduction:** {row['Error_Reduction_%']:.1f}%
"""))
model_dropdown.observe(show_model_metrics, names='value')
display(model_dropdown, output)
🧩 “Interactivity turns a static notebook into a Netflix for data nerds.”
🧪 Step 6. Create the Business Summary#
Use Markdown, visuals, and plain language to summarize:
“The Random Forest model achieved the best tradeoff between accuracy and interpretability, improving forecast precision by 25% over the baseline. This translates into an estimated $420K reduction in overstock costs.” 💰
💬 “A good dashboard answers questions. A great one creates budget justification.” 😏
🧠 Practice Tasks#
🎯 Level 1 – Warm-Up:
Load your own dataset from a previous exercise (e.g. regression or classification).
Compute RMSE, MAE, R², and display them in a Plotly bar chart.
🎯 Level 2 – Business Twist:
Add calculated “error reduction %” or “accuracy gain %”.
Annotate results with business insights.
🎯 Level 3 – Dashboard Hero:
Add filters for business units or time periods.
Include a “summary text” explaining the best model choice.
Style it with emojis, colors, or icons (CFOs love polish).
🧭 Recap#
Step |
Skill |
Output |
|---|---|---|
1 |
Load performance data |
Pandas DataFrame |
2 |
Compute KPIs |
Derived metrics |
3 |
Visualize |
Plotly charts |
4 |
Summarize |
KPI cards |
5 |
Interact |
Filters & widgets |
6 |
Communicate |
Business insights |
7 |
Share |
Dashboard ready |
💬 Final Thought#
“Your dashboard isn’t just about showing numbers — it’s about telling the story of your model’s impact on business.” 📈
🔜 Next Up#
👉 In the next chapter — Core ML Models — we’ll go from measuring models to building them. Get ready to meet Regression, Classification, and their weird cousin, Clustering — and find out why every ML algorithm has trust issues with your data. 😜
# Your code here