HSMA 8B - Forecasting

Running the code

Warning

Due to some environment issues that have not been fully resolved, you may run into issues on some platforms when running the code. This is due to some changes in newer versions of packages that were necessary to include for compatability reasons.

For now, I would recommend just watching the lecture videos.

However, if you are keen to still try the exercises/code-alongs but run into issues, I would recommend skipping to the next part of the exercise/code-along notebook or the next exercise/code-along notebook.

For all code-along notebooks and exercises, you have several options.

  • Run it locally on your machine using the hsma_forecast environment

    • Note that due to some big packages, this may take longer than usual to install
  • Run the exercises in colab using the buttons next to each exercise on this page

  • Run the exercises in Github Codespaces, which will give you access to a virtual version of VSCode running in the cloud.

    • Click on ‘Use this template’ and ‘Open in a codespace’
    • Initial setup may take ~5 minutes - when it is ready, you will see the contents of the repository on the left
    • When prompted within the environment to pick a kernel, choose ‘Python environments’ and ‘Python 3.11.10’
    • If you need to return to the same codespace later, choose ‘Code’ and ‘Codespaces’, then click the codespace under ‘on current branch’. Yours will have a different autogenerated name.

Part 1 - Introduction to Forecasting Principles and Naive Models

  • Watch the recording of the lecture from last year.

https://www.youtube.com/watch?v=akkG4XOf-_E

Slides for part 1: https://github.com/hsma-programme/8b_forecasting/blob/main/HSMA%205%20Slides%20-%20Part%201%20-%20Intro%20to%20Forecasting.pdf

Warning

Due to some environment issues that have not been fully resolved, you may run into issues on some platforms when running the code. This is due to some changes in newer versions of packages that were necessary to include for compatability reasons.

For now, I would recommend just watching the lecture videos.

However, if you are keen to still try the exercises/code-alongs but run into issues, I would recommend skipping to the next part of the exercise/code-along notebook or the next exercise/code-along notebook.

  • Work through the code-along notebooks that Elliott goes through in the video

    • examples/01_pandas_time_series.ipynb Open In Colab

    • examples/02_exploring_ts.ipynb Open In Colab

    • examples/03_benchmark_forecasts.ipynb Open In Colab

  • Have a go at the exercises

    • exercises/1_exploring_time_series_data.ipynb Open In Colab
    • exercises/2_naive_models.ipynb Open In Colab
  • Solutions are provided in the solutions folder.

    • solutions/1_exploring_time_series_data.ipynb Open In Colab
    • solutions/2_naive_models.ipynb Open In Colab

Part 2 - Forecasting with the Prophet library

  • Watch the recording of the lecture from last year.

https://www.youtube.com/watch?v=6vFpnSYlUyI

Slides for part 2: https://github.com/hsma-programme/8b_forecasting/blob/main/HSMA%205%20Slides%20-%20Part%202%20-%20Forecasting%20with%20Prophet.pdf

Tip

In the video, Elliott uses v1.0.0 of Prophet. The environment contains a newer version this year that should have Mac chip compatability

Warning

Due to some environment issues that have not been fully resolved, you may run into issues on some platforms when running the code. This is due to some changes in newer versions of packages that were necessary to include for compatability reasons.

For now, I would recommend just watching the lecture videos.

However, if you are keen to still try the exercises/code-alongs but run into issues, I would recommend skipping to the next part of the exercise/code-along notebook or the next exercise/code-along notebook.

  • Work through the code-along notebooks that Elliott goes through in the video

    • examples/04_prophet_1_preprocessing.ipynb Open In Colab

    • examples/05_prophet_2_basic_prophet_model.ipynb Open In Colab

    • examples/06_prophet_3_prophet_with_holidays.ipynb Open In Colab

  • Have a go at the exercise

    • exercises/3_forecasts_with_prophet.ipynb Open In Colab
  • Solutions are provided in the solutions folder.

    • solutions/3_forecasts_with_prophet.ipynb Open In Colab

Optional Bonus Reading and Videos

If you are interested in learning more about forecasting, here are some additional resources.

Book - Forecasting: Principles and Practice

While this eBook is R-focussed, it’s a great overview of various elements of forecasting.

https://otexts.com/fpp3/

There is a repository of Python equivalent code.

https://github.com/zgana/fpp3-python-readalong

Videos - Advanced forecasting methods

These additional videos are completely optional and only recommended if this is an area you are extremely interested in - even then, Prophet may be sufficient for your use case, and you should be warned that the code used in these videos is complex!

Auto-regressive Forecasting using OLS

You can download the notebook here:

https://github.com/health-data-science-OR/forecasting/blob/master/05_autoregression/autoregression1.ipynb

Using Feedforward neural networks for forecasting

You can explore a range of notebooks here:

https://github.com/health-data-science-OR/forecasting/tree/master/06_neural_networks