Time-Series Modelling with Python
About this course
Most forecasting mistakes come from treating time-stamped data like any other table. Each observation depends on the ones before it, so a random train/test split quietly lets a model see the future. Seasonality, holidays and calendar effects can make a weak model look good, and gaps and mismatched timestamps break the joins a forecast depends on. This course teaches you to handle time-stamped data correctly in Python and to build forecasts and models you can defend.
Day One focuses on working with time-series data in Pandas. This includes how to parse dates and times, deal with irregularly spaced data, align datasets with mismatched timestamps, and fix missing values. We then plot the results, surveying the main plotting libraries and focusing on Plotly for high-quality interactive charts. Other libraries, such as Matplotlib, can be covered on request.
On Day Two we build models of the data. We start with baseline models and classical statistical approaches in statsmodels: testing for stationarity, reading autocorrelation plots, fitting ARIMA and GARCH models, adding external drivers such as weather or holidays with SARIMAX, and checking the residuals. From there we compare the automated tools pmdarima, Prophet and Darts, and see how to treat forecasting as a machine learning problem with scikit-learn.
Throughout, models are judged on time-ordered validation, which guards against an overconfident model that looks good in the notebook and fails in production.
Bring your own datasets and we will work through them with you. Our trainers build models like these in their own work, so you can ask how to apply each method to the problems you actually have. You'll leave able to clean, model and forecast time-series data, and to justify your modelling decisions.
Who this course is for
Analysts, scientists, engineers and finance staff who work with time-series data. This includes sensor and instrument readings, hydrological and climate records, prices and returns, and demand and usage figures. The course suits people who have outgrown a spreadsheet trend line or a single moving average, and need a forecast whose assumptions they can check.
This course also suits teams that produce forecasts other people plan around, and want a shared, defensible way of building and validating their models.
Prerequisites
This course is designed to be able to be completed immediately after completing Python Charmers' Introduction to Python course, or equivalent programming experience (approximately 3 months of regular usage).
You should be comfortable loading and filtering data in Pandas, Polars or an equivalent DataFrame package. No prior time-series or forecasting experience is assumed. The statistics the models rely on, such as stationarity tests, autocorrelation and information criteria, are introduced as they are needed.
What you will learn
- Load, clean and align time-stamped data from several sources, including series recorded at different frequencies or in different timezones.
- Resample, smooth and plot a series to expose its trend, seasonality and anomalies before modelling it.
- Test a series for stationarity and use autocorrelation plots to choose a model's order.
- Fit and compare ARIMA-family and GARCH models, including models with external drivers, and check the residuals to confirm the model fits.
- Evaluate a forecast against a baseline using time-ordered validation, and explain its prediction intervals to the people who rely on it.
- Save a fitted model so it can produce forecasts outside the notebook it was built in.
Syllabus
Day 1: Working with time-series data in Pandas
- Parsing dates reliably, timestamp resolution, and handling timezones
- Indexing, resampling and frequency conversion with timestamps and periods
- Rolling, expanding and exponentially weighted windows
- Business-day calendars, and grouping by time alongside other keys
- Joining series whose timestamps do not match, with
merge_asof - Missing and abnormal values: filling, interpolation, and limiting how far a fill reaches
- Visualising time series: seasonal plots, heat maps, differencing and the frequency spectrum
- Interactive charts with Plotly, including series with millions of points
Day 2: Modelling and forecasting
- Decomposing a series into trend, seasonality and residual, and setting a baseline to beat
- Stationarity, differencing and the augmented Dickey-Fuller test
- Autocorrelation and partial autocorrelation for choosing a model order
- AR, MA, ARMA and seasonal ARIMA models in statsmodels, compared by AIC and checked with residual diagnostics
- External drivers such as weather, promotions and holidays, with SARIMAX
- Modelling volatility with GARCH
- Automated model selection and probabilistic forecasts with pmdarima, Prophet and Darts
- Non-linear and machine learning models, with time-ordered cross-validation
- Putting a forecasting model into production