1 / 11
Learn time series forecasting in Python by building a complete demand forecasting system: pandas for dated data, decomposition, baselines and error metrics, exponential smoothing, ARIMA and SARIMAX with holidays and promotions, rolling-origin backtests, feature engineering and gradient boosting…
Predict Demand with pandas, statsmodels, scikit-learn, and PyTorch
Read before you buy: the PDF here is a free sample — the first 20 pages of the 428-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
Forecasts you can measure, explain, and trust — from the first baseline to a pipeline that runs every week.
Every business makes forecasts: how much to bake, stock, staff, or ship. Python gives you an excellent toolkit for doing it well, but the hard part is not calling fit(). It is framing the problem, avoiding the subtle ways a model can peek at the future, choosing honest metrics, comparing models fairly, expressing uncertainty, and turning a forecast into a decision.
This book teaches all of it with one realistic project. Every model is evaluated on the same data, the same test window, and the same rolling-origin backtest, so you see exactly what each technique buys you — and when a simpler method is good enough.
What's inside
- Framing forecasting problems: target, horizon, granularity, and the decision a forecast supports
- Time series in pandas: dates, frequencies, resampling, closed days versus missing data, and clear charts
- Trend, seasonality, STL decomposition, and autocorrelation in plain language
- Baselines (naive, seasonal naive, averages, drift) and metrics (MAE, RMSE, MAPE, sMAPE, WAPE, MASE) with their traps
- Exponential smoothing and ETS, stationarity and ARIMA, and SARIMAX with holiday, promotion, and Fourier regressors
- Validation done right: time-based splits and rolling-origin backtests instead of random cross-validation
- Leak-free feature engineering — lags, rolling windows, calendar, holidays, promotions — and gradient boosting with scikit-learn
- Global models that learn from all series at once, including a shop with a short history
- Multi-step strategies: recursive, direct, and multi-output forecasting
- Deep learning on a CPU with PyTorch: a sequence-to-sequence LSTM with known future covariates and a tiny Transformer, with an honest comparison
- Probabilistic forecasts: prediction intervals, quantile regression, pinball loss, conformal prediction, and calibration checks
- Hierarchical forecasting: bottom-up, top-down, OLS, WLS, and MinT reconciliation
- Anomalies and data quality, intermittent demand (Croston, SBA, TSB), and cold starts
- From forecast to decision: newsvendor bake plans, service levels, waste, and profit
- Production: project structure, configuration, tests, batch runs, an API, monitoring, drift, and retraining
One running example, start to finish. You build the forecasting system for Bramblecrest Bakery, a fictional bakery with four shops and six products — 24 daily demand series with weekly and yearly seasonality, holidays, promotions, a newly opened shop, and the data problems real sales exports always have. The data comes from a seeded generator included with the book, so every number you read can be reproduced exactly on your own computer, and every result in the book was produced by running the book's code.
Current and honest. The code targets Python 3.12 with recent versions of pandas, statsmodels, scikit-learn, and PyTorch, and runs on an ordinary CPU in minutes. The book contains no invented benchmarks or statistics: every metric comes from the book's own synthetic data, and the comparisons show where fancy models win, where they lose, and by how much. Every chapter includes runnable code, Tips, Notes, Warnings, exercises, and Key Takeaways, and the appendices give you a cheat sheet, templates and reference tables, a production checklist, and a glossary.
Format: PDF, 428 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. This book is independent and is not affiliated with, sponsored by, or endorsed by the Python Software Foundation, The Linux Foundation, or any library project mentioned.
Table of Contents
Part I — Foundations
- Ch 1 · What Forecasting Is: Problems, Horizons, and the Bramblecrest Project
- Ch 2 · Time Series Data with pandas: Dates, Frequencies, and Missing Days
- Ch 3 · Visualizing Time Series: Line, Seasonal, and Calendar Plots
- Ch 4 · Decomposition and Patterns: Trend, Seasonality, STL, and Autocorrelation
- Ch 5 · Baselines and Forecast Accuracy: Naive Methods and Error Metrics
Part II — Statistical Forecasting
- Ch 6 · Exponential Smoothing: Simple, Holt, Holt-Winters, and ETS
- Ch 7 · Stationarity, Differencing, and ARIMA
- Ch 8 · SARIMAX: Seasonality, Holidays, Promotions, and Fourier Terms
- Ch 9 · Validation Done Right: Time-Based Splits and Rolling-Origin Backtests
- Ch 10 · Diagnosing Statistical Models: Residuals, Information Criteria, and Intervals
Part III — Machine Learning Forecasting
- Ch 11 · Forecasting as Supervised Learning: Windows, Lags, and Leakage
- Ch 12 · Feature Engineering: Lags, Rolling Windows, Calendar, Holidays, and Promotions
- Ch 13 · Gradient Boosting Forecasts with scikit-learn
- Ch 14 · Global Models: One Model for Many Series
- Ch 15 · Multi-Step Strategies: Recursive, Direct, and Multi-Output
Part IV — Deep Learning
- Ch 16 · Neural Networks for Sequences in PyTorch
- Ch 17 · LSTM Forecasting: A Sequence-to-Sequence Model with Covariates
- Ch 18 · Attention and Small Transformers for Time Series
- Ch 19 · Deep Learning in Practice: Scaling, Tuning, and When It Pays Off
Part V — Uncertainty and Structure
- Ch 20 · Probabilistic Forecasts: Intervals, Quantiles, and Pinball Loss
- Ch 21 · Conformal Prediction and Calibration
- Ch 22 · Hierarchical Forecasting and Reconciliation
- Ch 23 · Anomalies, Outliers, and Data Quality
Part VI — Forecasting in Production
- Ch 24 · Intermittent and New-Product Demand: Croston, Cold Starts, and Short Histories
- Ch 25 · From Forecast to Decision: Bake Plans, Service Levels, and Business Value
- Ch 26 · Building a Forecasting Pipeline: Structure, Configuration, and Tests
- Ch 27 · Deploying and Monitoring Forecasts: Batch Runs, APIs, Drift, and Retraining
- Ch 28 · Case Study: The Bramblecrest Forecasting System End to End
Appendices
A · Forecasting Cheat Sheet
B · Templates and Reference
C · Production Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 428 |
| Format | PDF (A4) |
| Language | English |
| Level | Beginner to Intermediate |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
Files you get
No reviews yet. Only buyers can review.
More from thenexbooks