How to forecast a number from its own past: the components of a time series, simple benchmark forecasts, exponential smoothing up to Holt-Winters, a fair test on a holdout, and the error measures that decide which forecast to trust. Then a Streamlit app that turns the forecast into an order.
Slides¶
Present full screen Download the PDF
Click or tap the slide to move forward, its left edge to go back; the arrow keys work too.
Reading¶
Forecasting Demand forecasts three years of Qahwa House’s weekly coffee beans: it separates the trend from the season, compares five methods on the last 8 weeks, shows why a holiday that moves trips up a forecast that copies last year, and turns the best forecast into an order for each branch.
Lab 8: Demand forecast app¶
At the end of July 2025, each branch orders its coffee beans for the next 8 weeks at once: too few and it runs out, too many and the beans go stale. How many kilograms should each branch order, and which forecasting method should decide? You test four methods on a holdout, choose an error measure, then write a Streamlit app in which the manager picks a branch, a method and a service level and reads off the order.
Open the lab, then use its Open in Colab button.
Data: qahwa
_weekly _demand .csv (624 rows: 156 weeks, August 2022 to July 2025, for 4 branches). The notebook downloads it by itself. Submit the notebook and your
forecast_app.pybefore the next lab session. The solutions are for checking your work afterwards.
Running the app¶
Colab cannot display a Streamlit page, so the lab tests the app with Streamlit’s AppTest. To see it in a browser:
GitHub Codespaces (free with GitHub Education) or your own computer: open a terminal in the folder with the app, run
pip install streamlit pandas statsmodels, thenstreamlit run forecast_app.py. A browser tab opens athttp://localhost:8501.Share it: push the app and a
requirements.txtto a GitHub repository and deploy it on Streamlit Community Cloud, choosing the repository and the file. You get a public link.
The finished course version, with every method’s holdout scores, the orders of all branches, a forecast horizon, a service level and a manual adjustment: app.py and its requirements.txt. In a clone of the course repository, run it with streamlit run week08/app/app.py.
Next week¶
Optimization modeling: decision variables, an objective and constraints, solved in Python with PuLP.