Skip to content

PacktPublishing/Time-Series-with-PyTorch

Repository files navigation

Time Series with PyTorch, First Edition

This is the code repository for Time Series with PyTorch, First Edition, published by Packt.

Modern Deep Learning Toolkit for Real-World Forecasting Challenges

Graeme Davidson, Lei Ma

      Free PDF       Graphic Bundle       Amazon      

About the book

Time Series with PyTorch, First Edition

Neural networks are powerful tools for time-series forecasting, but applying them effectively requires both practical experience and a clear understanding of architectures, training strategies, and evaluation methods. This book brings these ideas together in a structured and practical way. Starting with PyTorch fundamentals, you will build neural networks from scratch and progress through recurrent networks, attention mechanisms, and transformers before exploring forecasting architectures such as N-BEATS, N-HiTS, and the Temporal Fusion Transformer. Along the way, you will learn robust hyperparameter tuning, conformal prediction for uncertainty estimation, and reliable evaluation practices. Unlike most forecasting books, this text also explores topics often overlooked or treated separately, including transfer learning across collections of series, synthetic data generation with diffusion models, and self-supervised representation learning. Beyond forecasting, later chapters cover classification, clustering, anomaly detection, and embeddings for large-scale time-series modeling. Throughout, the focus is pragmatic: theory is reinforced through experimentation and implementation so you can apply these methods confidently to real-world time-series problems.

Key Learnings

  • Build, train, and evaluate neural networks for time series using PyTorch and PyTorch Lightning. Tune models with Bayesian optimisation and validate them with suitable metrics and strategies.
  • Progress from feedforward and recurrent networks to transformers and models such as N-BEATS, N-HiTS, and TFT.
  • Learn how global models use cross- and transfer learning across many series.
  • Generate synthetic series and representations with diffusion and self-supervised methods.
  • Apply modern approaches to classification, clustering, and anomaly detection.

Chapters

Unity Cookbook, Fifth Edition
  1. Time Series for Everyone
  2. The Challenge of Time Series
  3. Evaluating Time-Series Models
  4. PyTorch Fundamentals
  5. Simple Neural Architecture
  6. Optimization
  7. Conformal Prediction
  8. Recurrent Neural Networks
  9. Transformers
  10. Other Neural Structures
  11. Transfer Learning and Global Modelling
  12. Synthetic Time Series Data
  13. Diffusion Models
  14. Time Series Classification
  15. Time Series Clustering
  16. Embeddings for Time Series
  17. Supervised and Unsupervised Anomaly Detection
  18. Self-Supervised Learning for Time Series

Requirements for this book

To follow the code examples in this book, you will need a working Python 3.10+ environment with PyTorch installed. We recommend using a virtual environment manager such as Poetry, uv or conda. A CUDA-capable GPU is beneficial for the later chapters but is not strictly required — most examples can be run on CPU, though training times will be longer.

The book assumes you are comfortable reading and writing Python, including working with pandas DataFrames and NumPy arrays. Some familiarity with basic statistics (means, standard deviations, hypothesis testing) and machine learning concepts (overfitting, cross-validation, loss functions) will help, though we revisit these where relevant. You do not need prior experience with PyTorch or deep learning — Chapter 4 covers the fundamentals.

Key libraries used throughout include PyTorch, Nixtla’s statsforecast, NeuralForecast, and MLForecast, scikit-learn, aeon, stumpy, and matplotlib. Installation instructions and version requirements are provided at the start of each chapter.

Prerequisites

  • Python>=3.11
  • uv

How to run the code

  1. Install the required dependencies using uv:
    uv sync --all-groups
  2. Select the virtual environment created by uv in your IDE or terminal or jupyter.

Get to know Authors

Graeme Davidson is a Lead Data Scientist at Retail Express, where he redesigned the company's demand forecasting framework in line with contemporary statistical learning practices. His background spans cognitive neuroscience, researching implicit reward processing and human decision-making, through advertising analytics to research-focused demand forecasting. He is an active contributor to several data science Slack and Discord communities, an occasional competitor in forecasting competitions, and was approached by Packt in late 2022 to write the book he wished had existed when he first fell down an ARIMA rabbit hole chasing answers about how supermarkets actually forecast demand, and how a quantitative researcher models financial markets.

Lei Ma is a physicist-turned data scientist specializing in time series forecasting. He is theorist but has tackled real-world forecasting challenges across a variety of industries like housing, logistics, ecommerce, and manufacturing. Lei has led and delivered numerous forecasting projects where he combines deep expertise in building advanced time series models with a strategic approach to delivering holistic business insights. Lei creates time series forecasting tutorials online and joined the venture when Graeme approached him to collaborate on this book.

Other Related Books

About

Time Series with PyTorch, Published by Packt

Resources

License

Stars

27 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors