BEGINNER • Python Data Foundation
Feature Quality Checkpoint #8
This lesson focuses on reduce business risk in predictions using a practical energy usage forecasting scenario. You will apply commands: plt.plot() | pip install pandas numpy matplotlib seaborn | python script.py. The code example demonstrates a concrete workflow aligned with this lesson objective, not generic filler.
Code Example
import pandas as pd
events = pd.DataFrame({
"model_version": ["v1", "v1", "v2", "v2", "v2", "v3"],
"latency_ms": [110, 130, 95, 102, 99, 140],
"is_error": [0, 0, 0, 1, 0, 1],
})
def monitoring_report(frame: pd.DataFrame):
grouped = frame.groupby("model_version").agg(
avg_latency=("latency_ms", "mean"),
error_rate=("is_error", "mean"),
calls=("model_version", "count"),
)
return grouped.reset_index().to_dict(orient="records")
print("scenario:", "energy usage forecasting")
print(monitoring_report(events))Commands & References
- plt.plot()
- pip install pandas numpy matplotlib seaborn
- python script.py
Lab Steps
- Prepare environment using: plt.plot()
- Load a small sample dataset and validate schema.
- Run the core code workflow and collect metrics.
- Compare results and write one improvement note.
Exercises
- Change one hyperparameter and compare impact.
- Add one validation rule to reduce bad inputs.
- Document one failure mode and mitigation.