Reader small image

You're reading from  Deep Learning for Time Series Cookbook

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781805129233
Edition1st Edition
Right arrow
Authors (2):
Vitor Cerqueira
Vitor Cerqueira
author image
Vitor Cerqueira

​Vitor Cerqueira is a time series researcher with an extensive background in machine learning. Vitor obtained his Ph.D. degree in Software Engineering from the University of Porto in 2019. He is currently a Post-Doctoral researcher in Dalhousie University, Halifax, developing machine learning methods for time series forecasting. Vitor has co-authored several scientific articles that have been published in multiple high-impact research venues.
Read more about Vitor Cerqueira

Luís Roque
Luís Roque
author image
Luís Roque

Luís Roque, is the Founder and Partner of ZAAI, a company focused on AI product development, consultancy, and investment in AI startups. He also serves as the Vice President of Data & AI at Marley Spoon, leading teams across data science, data analytics, data product, data engineering, machine learning operations, and platforms. In addition, he holds the position of AI Advisor at CableLabs, where he contributes to integrating the broadband industry with AI technologies. Luís is also a Ph.D. Researcher in AI at the University of Porto's AI&CS lab and oversees the Data Science Master's program at Nuclio Digital School in Barcelona. Previously, he co-founded HUUB, where he served as CEO until its acquisition by Maersk.
Read more about Luís Roque

View More author details
Right arrow

Preface

The writing of this book was motivated by the increasing demand for practical approaches to time series analysis and forecasting. Organizations across various sectors rely on time series analysis to gain insights into their operations. By leveraging time series, these organizations can make informed decisions and optimize their performance. Accurate forecasts are valuable assets across many application domains, such as retail or economics. These predictions help reduce uncertainty and enable better planning of operations. Overall, time series analysis is a valuable skill for data scientists to understand and extract meaningful insights from collections of observations that evolve over time.

Meanwhile, deep learning is driving recent important scientific and technological advances. It is a subset of machine learning and artificial intelligence where models are based on artificial neural networks. Deep learning is foundational to many technologies we use and hear about today, including ChatGPT, self-driving cars, and advanced image recognition tools. At the same time, deep learning methods require significant technical expertise to produce meaningful results.

This book guides machine learning practitioners and enthusiasts interested in applying deep learning to learn from time series data. We present clear and easy-to-follow code recipes for applying deep learning to time series data. While the content is tailored for beginners, more seasoned machine learning professionals can also find value in the nuances of more advanced techniques. The book presents a learn-by-doing approach to ensure that you not only understand the main concepts but also know how to apply them effectively.

The book covers several popular time series problems, such as forecasting, anomaly detection, and classification. These tasks are solved with different deep neural network architectures, including convolutional neural networks or transformers. We use the PyTorch ecosystem, a popular deep learning framework based on Python.

By the end of this book, you’ll be able to solve different time series tasks using deep learning methods.

Who this book is for

This book is primarily designed for beginners to data science, and those who are eager to delve into the application of deep learning for time series analysis and forecasting. We assume that you have a basic understanding of Python, which will help you to navigate the coding recipes more easily. We also rely on popular data manipulation libraries such as pandas and NumPy. So, a familiarity with these will improve your reading experience.

We expect you to have basic knowledge concerning fundamental machine learning concepts and techniques. Understanding things such as supervised and unsupervised learning, as well as being familiar with classification, regression, cross-validation, and evaluation methodologies, is important to get the most out of this book.

What this book covers

Chapter 1, Getting Started with Time Series, introduces the main concepts behind time series. The chapter starts by defining a time series and describing how it can represent several real-world systems. Then, we explore the main features of time series data, including trend or seasonality. You’ll also learn about several methods and techniques for time series analysis.

Chapter 2, Getting Started with PyTorch, provides an overview of how to use PyTorch to develop deep learning models in Python. We start by guiding you through the installation process of PyTorch, including how to set up the appropriate environment. This is followed by an introduction to defining a neural network structure in PyTorch, including the definition of layers and activation functions. Afterward, we walk through the process of training a neural network. By the end of the chapter, you will understand the fundamentals of using PyTorch for deep learning and be ready to tackle forecasting tasks with these new skills.

Chapter 3, Univariate Time Series Forecasting, focuses on using PyTorch to develop deep learning forecasting models for univariate time series. We begin by guiding you through preparing a time series for supervised learning. After that, we introduce different types of neural networks, including feed-forward, recurrent, and convolutional neural networks. We explain how they can be trained and how we can use them to tackle time series forecasting problems. We also cover common time series issues, such as trend and seasonality, and how to incorporate them into neural network models.

Chapter 4, Forecasting with PyTorch Lightning, explores the PyTorch Lightning ecosystem and how to use it to build neural networks using time series. You’ll learn about data modules and data loaders, and how these can help you accelerate the process of building forecasting models. We also explore TensorBoard and callbacks, which are useful to drive the training process.

Chapter 5, Global Forecasting Models, describes how to handle forecasting problems involving collections of time series. You’ll also learn about the intricacies of particular problems in forecasting, such as multi-step ahead predictions and predictions for multiple variables. Finally, we’ll also explore how to optimize the parameters of a neural network using Ray Tune.

Chapter 6, Advanced Deep Learning Architectures for Time Series Forecasting, provides a comprehensive guide to using state-of-the-art architectures for time series forecasting. We cover how to train several models, such as DeepAR, N-BEATS, and TFT. Additionally, we explain each model’s architecture and inner workings and how to apply them to specific forecasting problems.

Chapter 7, Probabilistic Time Series Forecasting, describes how to use deep learning for probabilistic time series forecasting. We introduce the concept of probabilistic forecasting and the key differences compared to traditional point forecasting. The chapter gives several examples of probabilistic forecasting problems that can be tackled using specific deep learning architectures.

Chapter 8, Deep Learning for Time Series Classification, focuses on using deep learning to tackle time series classification problems. The chapter introduces the concept of time series classification, which involves assigning a class label to a time series. We show how to tackle time series classification problems with different deep learning architectures, including residual and convolutional neural networks.

Chapter 9, Deep Learning for Time Series Anomaly Detection, gives an overview of how to use deep learning to detect abnormal patterns in a time series. For this use case, we introduce generative adversarial networks and auto-encoders, which are popular approaches to detecting anomalies in time series.

To get the most out of this book

We assume that you have basic knowledge of Python, data science, and machine learning. Coding and data manipulation using libraries such as NumPy or pandas should be familiar for a comfortable read. Readers should also know about basic concepts and techniques behind machine learning, including supervised and unsupervised learning, classification, regression, cross-validation, and evaluation.

Software/hardware covered in the book

OS requirements

Python (3.9)

Windows, Mac OS X, or Linux (any)

PyTorch Lightning (2.1.2)

pandas (>=2.1)

scikit-learn (1.3.2)

NumPy (1.26.2)

torch (2.1.1)

PyTorch Forecasting (1.0.0)

GluonTS (0.14.2)

Further requirements will be detailed in the introduction of the chapters.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Deep-Learning-for-Time-Series-Data-Cookbook. If there’s an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The main component of this module is the setup() method.”

A block of code is set as follows:

from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(x=series_daily, model='additive', period=365)

Any command-line input or output is written as follows:

pip install pyod

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There’s more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There’s more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Deep Learning for Time Series Cookbook, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/978-1-80512-923-3

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Deep Learning for Time Series Cookbook
Published in: Mar 2024Publisher: PacktISBN-13: 9781805129233
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Vitor Cerqueira

​Vitor Cerqueira is a time series researcher with an extensive background in machine learning. Vitor obtained his Ph.D. degree in Software Engineering from the University of Porto in 2019. He is currently a Post-Doctoral researcher in Dalhousie University, Halifax, developing machine learning methods for time series forecasting. Vitor has co-authored several scientific articles that have been published in multiple high-impact research venues.
Read more about Vitor Cerqueira

author image
Luís Roque

Luís Roque, is the Founder and Partner of ZAAI, a company focused on AI product development, consultancy, and investment in AI startups. He also serves as the Vice President of Data & AI at Marley Spoon, leading teams across data science, data analytics, data product, data engineering, machine learning operations, and platforms. In addition, he holds the position of AI Advisor at CableLabs, where he contributes to integrating the broadband industry with AI technologies. Luís is also a Ph.D. Researcher in AI at the University of Porto's AI&CS lab and oversees the Data Science Master's program at Nuclio Digital School in Barcelona. Previously, he co-founded HUUB, where he served as CEO until its acquisition by Maersk.
Read more about Luís Roque