
Machine Learning for Time Series Forecasting with Python
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Machine Learning for Time Series Forecasting with Python is an incisive and straightforward examination of one of the most crucial elements of decision-making in finance, marketing, education, and healthcare: time series modeling.
Despite the centrality of time series forecasting, few business analysts are familiar with the power or utility of applying machine learning to time series modeling. Author Francesca Lazzeri, a distinguished machine learning scientist and economist, corrects that deficiency by providing readers with comprehensive and approachable explanation and treatment of the application of machine learning to time series forecasting.
Written for readers who have little to no experience in time series forecasting or machine learning, the book comprehensively covers all the topics necessary to:
* Understand time series forecasting concepts, such as stationarity, horizon, trend, and seasonality
* Prepare time series data for modeling
* Evaluate time series forecasting models' performance and accuracy
* Understand when to use neural networks instead of traditional time series models in time series forecasting
Machine Learning for Time Series Forecasting with Python is full real-world examples, resources and concrete strategies to help readers explore and transform data and develop usable, practical time series forecasts.
Perfect for entry-level data scientists, business analysts, developers, and researchers, this book is an invaluable and indispensable guide to the fundamental and advanced concepts of machine learning applied to time series modeling.
More details
Other editions
Additional editions

Person
Content
Introduction xv
Chapter 1 Overview of Time Series Forecasting 1
Flavors of Machine Learning for Time Series Forecasting 3
Supervised Learning for Time Series Forecasting 14
Python for Time Series Forecasting 21
Experimental Setup for Time Series Forecasting 24
Conclusion 26
Chapter 2 How to Design an End-to-End Time Series Forecasting Solution on the Cloud 29
Time Series Forecasting Template 31
Business Understanding and Performance Metrics 33
Data Ingestion 36
Data Exploration and Understanding 39
Data Pre-processing and Feature Engineering 40
Modeling Building and Selection 42
An Overview of Demand Forecasting Modeling Techniques 44
Model Evaluation 46
Model Deployment 48
Forecasting Solution Acceptance 53
Use Case: Demand Forecasting 54
Conclusion 58
Chapter 3 Time Series Data Preparation 61
Python for Time Series Data 62
Common Data Preparation Operations for Time Series 65
Time stamps vs. Periods 66
Converting to Timestamps 69
Providing a Format Argument 70
Indexing 71
Time/Date Components 76
Frequency Conversion 78
Time Series Exploration and Understanding 79
How to Get Started with Time Series Data Analysis 79
Data Cleaning of Missing Values in the Time Series 84
Time Series Data Normalization and Standardization 86
Time Series Feature Engineering 89
Date Time Features 90
Lag Features and Window Features 92
Rolling Window Statistics 95
Expanding Window Statistics 97
Conclusion 98
Chapter 4 Introduction to Autoregressive and Automated Methods for Time Series Forecasting 101
Autoregression 102
Moving Average 119
Autoregressive Moving Average 120
Autoregressive Integrated Moving Average 122
Automated Machine Learning 129
Conclusion 136
Chapter 5 Introduction to Neural Networks for Time Series Forecasting 137
Reasons to Add Deep Learning to Your Time Series Toolkit 138
Deep Learning Neural Networks Are Capable of Automatically Learning and Extracting Features from Raw and Imperfect Data 140
Deep Learning Supports Multiple Inputs and Outputs 142
Recurrent Neural Networks Are Good at Extracting Patterns from Input Data 143
Recurrent Neural Networks for Time Series Forecasting 144
Recurrent Neural Networks 145
Long Short-Term Memory 147
Gated Recurrent Unit 148
How to Prepare Time Series Data for LSTMs and GRUs 150
How to Develop GRUs and LSTMs for Time Series Forecasting 154
Keras 155
TensorFlow 156
Univariate Models 156
Multivariate Models 160
Conclusion 164
Chapter 6 Model Deployment for Time Series Forecasting 167
Experimental Set Up and Introduction to Azure Machine Learning SDK for Python 168
Workspace 169
Experiment 169
Run 169
Model 170
Compute Target, RunConfiguration, and ScriptRun Config 171
Image and Webservice 172
Machine Learning Model Deployment 173
How to Select the Right Tools to Succeed with Model Deployment 175
Solution Architecture for Time Series Forecasting with Deployment Examples 177
Train and Deploy an ARIMA Model 179
Configure the Workspace 182
Create an Experiment 183
Create or Attach a Compute Cluster 184
Upload the Data to Azure 184
Create an Estimator 188
Submit the Job to the Remote Cluster 188
Register the Model 189
Deployment 189
Define Your Entry Script and Dependencies 190
Automatic Schema Generation 191
Conclusion 196
References 197
Index 199
CHAPTER 1
Overview of Time Series Forecasting
Time series is a type of data that measures how things change over time. In a time series data set, the time column does not represent a variable per se: it is actually a primary structure that you can use to order your data set. This primary temporal structure makes time series problems more challenging as data scientists need to apply specific data preprocessing and feature engineering techniques to handle time series data.
However, it also represents a source of additional knowledge that data scientists can use to their advantage: you will learn how to leverage this temporal information to extrapolate insights from your time series data, like trends and seasonality information, to make your time series easier to model and to use it for future strategy and planning operations in several industries. From finance to manufacturing and health care, time series forecasting has always played a major role in unlocking business insights with respect to time.
Following are some examples of problems that time series forecasting can help you solve:
- What are the expected sales volumes of thousands of food groups in different grocery stores next quarter?
- What are the resale values of vehicles after leasing them out for three years?
- What are passenger numbers for each major international airline route and for each class of passenger?
- What is the future electricity load in an energy supply chain infrastructure, so that suppliers can ensure efficiency and prevent energy waste and theft?
The plot in Figure 1.1 illustrates an example of time series forecasting applied to the energy load use case.
Figure 1.1: Example of time series forecasting applied to the energy load use case
This first chapter of the book is dedicated to the conceptual introduction-with some practical examples-of time series, where you can learn the essential aspects of time series representations, modeling, and forecasting.
Specifically, we will discuss the following:
- Flavors of Machine Learning for Time Series Forecasting - In this section, you will learn a few standard definitions of important concepts, such as time series, time series analysis, and time series forecasting, and discover why time series forecasting is a fundamental cross-industry research area.
- Supervised Learning for Time Series Forecasting - Why would you want to reframe a time series forecasting problem as a supervised learning problem? In this section you will learn how to reshape your forecasting scenario as a supervised learning problem and, as a consequence, get access to a large portfolio of linear and nonlinear machine learning algorithms.
- Python for Time Series Forecasting - In this section we will look at different Python libraries for time series data and how libraries such as pandas, statsmodels, and scikit-learn can help you with data handling, time series modeling, and machine learning, respectively.
- Experimental Setup for Time Series Forecasting - This section will provide you general advice for setting up your Python environment for time series forecasting.
Let's get started and learn some important elements that we must consider when describing and modeling a time series.
Flavors of Machine Learning for Time Series Forecasting
In this first section of Chapter 1, we will discover together why time series forecasting is a fundamental cross-industry research area. Moreover, you will learn a few important concepts to deal with time series data, perform time series analysis, and build your time series forecasting solutions.
One example of the use of time series forecasting solutions would be the simple extrapolation of a past trend in predicting next week hourly temperatures. Another example would be the development of a complex linear stochastic model for predicting the movement of short-term interest rates. Time-series models have been also used to forecast the demand for airline capacity, seasonal energy demand, and future online sales.
In time series forecasting, data scientists' assumption is that there is no causality that affects the variable we are trying to forecast. Instead, they analyze the historical values of a time series data set in order to understand and predict their future values. The method used to produce a time series forecasting model may involve the use of a simple deterministic model, such as a linear extrapolation, or the use of more complex deep learning approaches.
Due to their applicability to many real-life problems, such as fraud detection, spam email filtering, finance, and medical diagnosis, and their ability to produce actionable results, machine learning and deep learning algorithms have gained a lot of attention in recent years. Generally, deep learning methods have been developed and applied to univariate time series forecasting scenarios, where the time series consists of single observations recorded sequentially over equal time increments (Lazzeri 2019a).
For this reason, they have often performed worse than naïve and classical forecasting methods, such as exponential smoothing and autoregressive integrated moving average (ARIMA). This has led to a general misconception that deep learning models are inefficient in time series forecasting scenarios, and many data scientists wonder whether it's really necessary to add another class of methods, such as convolutional neural networks (CNNs) or recurrent neural networks (RNNs), to their time series toolkit (we will discuss this in more detail in Chapter 5, "Introduction to Neural Networks for Time Series Forecasting") (Lazzeri 2019a).
In time series, the chronological arrangement of data is captured in a specific column that is often denoted as time stamp, date, or simply time. As illustrated in Figure 1.2, a machine learning data set is usually a list of data points containing important information that are treated equally from a time perspective and are used as input to generate an output, which represents our predictions. On the contrary, a time structure is added to your time series data set, and all data points assume a specific value that is articulated by that temporal dimension.
Figure 1.2: Machine learning data set versus time series data set
Now that you have a better understanding of time series data, it is also important to understand the difference between time series analysis and time series forecasting. These two domains are tightly related, but they serve different purposes: time series analysis is about identifying the intrinsic structure and extrapolating the hidden traits of your time series data in order to get helpful information from it (like trend or seasonal variation-these are all concepts that we will discuss later on in the chapter).
Data scientists usually leverage time series analysis for the following reasons:
- Acquire clear insights of the underlying structures of historical time series data.
- Increase the quality of the interpretation of time series features to better inform the problem domain.
- Preprocess and perform high-quality feature engineering to get a richer and deeper historical data set.
Time series analysis is used for many applications such as process and quality control, utility studies, and census analysis. It is usually considered the first step to analyze and prepare your time series data for the modeling step, which is properly called time series forecasting.
Time series forecasting involves taking machine learning models, training them on historical time series data, and consuming them to forecast future predictions. As illustrated in Figure 1.3, in time series forecasting that future output is unknown, and it is based on how the machine learning model is trained on the historical input data.
Figure 1.3: Difference between time series analysis historical input data and time series forecasting output data
Different historical and current phenomena may affect the values of your data in a time series, and these events are diagnosed as components of a time series. It is very important to recognize these different influences or components and decompose them in order to separate them from the data levels.
As illustrated in Figure 1.4, there are four main categories of components in time series analysis: long-term movement or trend, seasonal short-term movements, cyclic short-term movements, and random or irregular fluctuations.
Figure 1.4: Components of time series
Let's have a closer look at these four components:
- Long-term movement or trend refers to the overall movement of time series values to increase or decrease during a prolonged time interval. It is common to observe trends changing direction throughout the course of your time series data set: they may increase, decrease, or remain stable at different moments. However, overall you will see one primary trend. Population counts, agricultural production, and items manufactured are just some examples of when trends may come into play.
- There are two different types of short-term movements:
- Seasonal variations are periodic temporal fluctuations that show the same variation and...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.