Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

8. Time-Series Forecasting

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.

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:

  1. 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, then streamlit run forecast_app.py. A browser tab opens at http://localhost:8501.

  2. Share it: push the app and a requirements.txt to 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.

→ Week 9: Optimization Modeling