Appendix A — Python Labs Summary
Python Labs Summary
This page collects the companion Python labs for Modern Time Series Analysis and Sequence Learning. Each lab is a Jupyter notebook stored in the labs/ folder of the book repository and can be opened directly in Google Colab.
Repository: https://github.com/wanghemath/Book-MachineLearning2sda
TipHow to use the labs
Use the Open in Colab link when reading the online book. In Colab, choose File \(\to\) Save a copy in Drive before editing. For local work, clone the repository and open the notebooks from the labs/ folder.
A.1 Lab table
| Chapter | Lab | Main focus |
|---|---|---|
| 1 | Why Time Series and Sequence Data Are Different Open in Colab |
simulate white noise, random walks, trend, seasonality, and windowed sequence data |
| 2 | Exploratory Data Analysis for Time Series Open in Colab |
time plots, smoothing, detrending, differencing, ACF, and seasonal diagnostics |
| 3 | Stationarity, Autocovariance, and Autocorrelation Open in Colab |
strict/weak stationarity examples, sample autocovariance, ACF, AR(1), MA(1), and random walk |
| 4 | Linear Processes, AR, MA, and ARMA Models Open in Colab |
simulate AR, MA, ARMA processes, root conditions, causality, invertibility, and ACF/PACF behavior |
| 5 | Difference Equations and Dynamic Behavior Open in Colab |
linear recurrences, characteristic roots, damping, oscillation, and explosive dynamics |
| 6 | Forecasting Theory and Best Linear Prediction Open in Colab |
best linear prediction, forecast variance, AR forecasts, and multi-step forecasting |
| 7 | Estimation, Identification, and Diagnostics Open in Colab |
Yule-Walker, likelihood, AIC/BIC, residual ACF, Ljung-Box, and model criticism |
| 8 | ARIMA Models and Differencing Open in Colab |
integrated processes, choosing differences, ARIMA fitting, over-differencing, and forecast reconstruction |
| 9 | Seasonal ARIMA and Multiple Seasonality Open in Colab |
seasonal differencing, SARIMA fitting, seasonal baselines, and residual diagnostics |
| 10 | State-Space Models and Kalman Filtering Open in Colab |
local-level models, Kalman prediction/update, missing data, smoothing, and state forecasts |
| 11 | Hidden Markov Models and Regime Switching Open in Colab |
forward probabilities, Viterbi decoding, Gaussian HMMs, and regime-switching simulations |
| 12 | Spectral Analysis and the Frequency Domain Open in Colab |
sinusoidal processes, aliasing, spectral density, and spectra of AR/MA models |
| 13 | Discrete Fourier Transform, FFT, and Periodogram Open in Colab |
DFT basis, FFT, periodogram, leakage, tapering, and peak detection |
| 14 | Filtering and Wavelet Transform Open in Colab |
linear filters, frequency response, differencing filters, Haar wavelets, and denoising |
| 15 | Forecast Evaluation and Backtesting Open in Colab |
rolling-origin validation, baseline comparisons, horizon-wise metrics, intervals, and leakage checks |
| 16 | Automated Forecasting and Prophet-Type Additive Models Open in Colab |
trend, changepoints, Fourier seasonality, holiday effects, Prophet-style models, and tuning |
| 17 | Feature-Based Machine Learning for Time Series Open in Colab |
lag features, rolling features, calendar variables, Fourier features, tree models, and validation |
| 18 | Probabilistic Forecasting and Uncertainty Quantification Open in Colab |
prediction intervals, quantile loss, conformal prediction, calibration, and risk decisions |
| 19 | Neural Networks for Time Series Open in Colab |
sliding windows, scaling, MLP forecasting, PyTorch training, and chronological validation |
| 20 | Convolutional Models for Sequences Open in Colab |
causal convolution, dilation, receptive fields, TCNs, and PyTorch Conv1d |
| 21 | Recurrent Neural Networks, LSTM, and GRU Open in Colab |
RNN hidden states, LSTM/GRU gates, sequence-to-one forecasting, and recurrent training |
| 22 | Attention and Transformer Models for Time Series Open in Colab |
scaled dot-product attention, causal masks, positional encodings, and transformer forecasting |
| 23 | Representation Learning for Time Series Open in Colab |
embeddings, PCA, autoencoders, masked reconstruction, contrastive ideas, and anomaly detection |
| 24 | Multivariate, Panel, and Hierarchical Time Series Open in Colab |
VAR models, coupling, Granger-style prediction, global models, and reconciliation |
| 25 | AI-Assisted Time-Series Modeling Open in Colab |
AI workflow auditing, prompt design, leakage review, code review, and report checking |
| 26 | End-to-End Forecasting Pipeline Open in Colab |
forecasting contracts, preprocessing, baselines, validation, intervals, and monitoring |
| 27 | Final Project Studio Open in Colab |
project design, validation planning, baselines, diagnostics, rubric alignment, and final reporting |
A.2 Lab design pattern
Most labs follow a common workflow:
- State the modeling question and identify the forecasting information set.
- Simulate or load a time-series/sequence dataset.
- Visualize the series, dependence structure, and diagnostics.
- Fit at least one baseline model before fitting a more advanced model.
- Evaluate with chronological or rolling-origin validation.
- Interpret residuals, uncertainty, and failure modes.
- Use AI assistance only after defining the mathematical task and then verify the output manually.
A.3 Recommended local setup
git clone https://github.com/wanghemath/Book-MachineLearning2sda.git
cd Book-MachineLearning2sda
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
jupyter labAlternatively, use Conda:
conda env create -f environment.yml
conda activate ts-sequence-learning
jupyter labA.4 Responsible AI checklist for labs
Before submitting any lab, verify the following.
- The train/validation/test split respects time order.
- Scaling, imputation, feature engineering, and model selection use only information available at the forecast origin.
- Every advanced model is compared with a baseline such as naive, seasonal naive, linear AR, ARIMA, or a simple feature model.
- Residuals or forecast errors are examined, not only point metrics.
- AI-generated code or explanations are checked against the mathematics and the data-generating process.
- The final notebook is reproducible from a clean runtime.