Preface
Mankind has always sought the ability to predict the future. Since the earliest civilizations, people have tried to predict the future. Shamans, oracles, and prophets used anything ranging from astrology and palmistry to numerology to satisfy the human need to see into the future. In the last century, with the developments in IT, the mantle of predicting the future landed on data analysts and data scientists. And how do we predict the future? It's not by examining the lines and creases on our hands or the positions of the stars anymore but by using data that has been generated in the past. And instead of prophecies, we now have forecasts.
Time, being the fourth dimension in our world, makes all the data generated in the world time series data. All the data that is generated in the real world has an element of time associated with it. Whether the temporal aspect is relevant to the problem or not is another question altogether. However, to be more concrete and immediate, we can find time series forecasting use cases in many industries, such as retail, energy, healthcare, and finance. We might want to know how many units of a particular product are to be dispatched to a particular store, or we might want to know how much electricity is to be produced to meet demand.
In this book, using a real-world dataset, you will learn how to handle and visualize time series data using pandas
and plotly
, generate baseline forecasts using darts
, and use machine learning and deep learning for forecasting, using popular Python libraries such as scikit-learn
and PyTorch
. We conclude the book with a few chapters that cover seldom-touched aspects, such as multi-step forecasting, forecast metrics and cross validation for time series.
The book will enable you to build real-world time series forecasting systems that scale to millions of time series by mastering and applying modern concepts in machine learning and deep learning.
Who this book is for
The book is ideal for data scientists, data analysts, machine learning engineers, and Python developers who want to build industry-ready time series models. Since the book explains most concepts from the ground up, basic proficiency in Python is all you need. A prior understanding of machine learning or forecasting would help speed up the learning. For seasoned practitioners in machine learning and forecasting, the book has a lot to offer in terms of advanced techniques and traversing the latest research frontiers in time series forecasting.
What this book covers
Part 1-Getting Familiar with Time Series
Chapter 1, Introducing Time Series, is all about introducing you to the world of time series. We lay down a definition of time series and talk about how it is related to a Data Generating Process (DGP). We will also talk about the limits of forecasting and talk about what we cannot forecast, and then we finish off the chapter by laying down some terminology that will help you understand the rest of the book.
Chapter 2, Acquiring and Processing Time Series Data, covers how you can process time series data. You will understand how different forms of time series data can be represented in a tabular form. You will learn different date-time-related functionalities in pandas
and learn how to fill in missing data using techniques suited for time series. Finally, using a real-world dataset, you will go through a step-by-step journey in processing time series data using pandas
.
Chapter 3, Analyzing and Visualizing Time Series Data, furthers your introduction to time series by learning how to visualize and analyze time series. You will learn different visualizations that are commonly used for time series data and then learn how to go one level deeper by decomposing time series into its components. To wrap it up, you will also look at ways to identify and treat outliers in time series data.
Chapter 4, Setting a Strong Baseline Forecast, gets right to the topic of time series forecasting as we use tried and tested methods from econometrics, such as ARIMA and exponential smoothing, to generate strong baselines. These efficient forecasting methods will provide strong baselines so that we can go beyond these classical techniques and learn modern techniques, such as machine learning. You will also get an introduction to another key topic-assessing forecastability using techniques such as spectral entropy and coefficient of variation.
Part 2-Machine Learning for Time Series
Chapter 5, Time Series Forecasting as Regression, starts our journey into using machine learning for forecasting. A short introduction to machine learning lays down the foundations of what is to come in the next chapters. You will also understand, conceptually, how we can cast a time series problem as a regression problem so that we can use machine learning for it. To close off the chapter, we tease you with the possibility of global forecasting models.
Chapter 6, Feature Engineering for Time Series Forecasting, shifts gear into a more practical lesson. Using a real-world dataset, you will learn about different feature engineering techniques, such as lag features, rolling features, and Fourier terms, which help us formulate a time series problem as a regression problem.
Chapter 7, Target Transformations for Time Series Forecasting, continues the practice of exploring different target transformations to accommodate non-stationarity in time series. You will learn techniques such as the augmented Dickey-Fuller test and Mann-Kendall test to identify and treat non-stationarity.
Chapter 8, Forecasting Time Series with Machine Learning Models, continues from where the last chapter left off to start training machine learning models on the dataset we have been working on. Using the standard code framework present in the book, you will train models such as linear regression, random forest, and gradient-boosted decision trees on our dataset.
Chapter 9, Ensembling and Stacking, takes a step back and explores how we can use multiple forecasts and combine them to create a better forecast. You will explore popular techniques such as best fit, different versions of the hill-climbing algorithm, simulated annealing, and stacking to combine the different forecasts we have generated to get a better one.
Chapter 10, Global Forecasting Models, concludes your guided journey into machine learning-enabled forecasting to an exciting and new paradigm-global forecasting models. You will learn how to use global forecasting models and industry-proven techniques to improve their performance, which finally lets you develop scalable and efficient machine learning forecasting systems for thousands of time series.
Part 3-Deep Learning for Time Series
Chapter 11, Introduction to Deep Learning, we switch tracks and start with a specific type of machine learning-deep learning. In this chapter, we lay the foundations of deep learning by looking at different topics such as representation learning, linear transformations, activation functions, and gradient descent.
Chapter 12, Building Blocks of Deep Learning for Time Series, continues the journey into deep learning by making it specific to time series. Keeping in mind the compositionality of deep learning systems, you will learn about different building blocks with which you can construct a deep learning architecture. The chapter starts off by establishing the encoder-decoder architecture and then talks about different blocks such as feed forward networks, recurrent neural networks, and convolutional neural networks.
Chapter 13, Common Modeling Patterns for Time Series, strengthens the encoder-decoder architecture that you saw in the previous chapter by showing you a few concrete and common patterns in which you can arrange building blocks to generate forecasts. This is a hands-on chapter where you will be creating forecasts using deep learning-based tabular regression and different sequence-to-sequence models.
Chapter 14, Attention and Transformers for Time Series, covers the contemporary topic of using attention to improve deep learning models. The chapter starts off by talking about a generalized attention model with which you will learn different types of attention schemes, such as scaled dot product and additive. You will also tweak the sequence-to-sequence models from the previous chapter to include attention and then train those models to generate a forecast. The chapter then talks about transformer models, which is a deep learning architecture that relies solely on attention, and then you will use that to generate forecasts as well.
Chapter 15, Strategies for Global Deep Learning Forecasting Models, tackles yet another important aspect of deep learning-based forecasting. Although the book talked about global forecasting models earlier, there are some differences in how it is implemented for deep learning models. In this chapter, you will learn how to implement global deep learning models and techniques...