Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions
By Ivan Gridin
()
About this ebook
The readers will learn the fundamentals of PyTorch in the early stages of the book. Next, the time series forecasting is covered in greater depth after the programme has been developed. You will try to use machine learning to identify the patterns that can help us forecast the future results. It covers methodologies such as Recurrent Neural Network, Encoder-decoder model, and Temporal Convolutional Network, all of which are state-of-the-art neural network architectures. Furthermore, for good measure, we have also introduced the neural architecture search, which automates searching for an ideal neural network design for a certain task.
Finally by the end of the book, readers would be able to solve complex real-world prediction issues by applying the models and strategies learnt throughout the course of the book. This book also offers another great way of mastering deep learning and its various techniques.
Read more from Ivan Gridin
Practical Deep Reinforcement Learning with Python: Concise Implementation of Algorithms, Simplified Maths, and Effective Use of TensorFlow and PyTorch (English Edition) Rating: 4 out of 5 stars4/5
Related to Time Series Forecasting using Deep Learning
Related ebooks
Deep Learning with Keras: Beginner’s Guide to Deep Learning with Keras Rating: 3 out of 5 stars3/5Mastering TensorFlow 2.x: Implement Powerful Neural Nets across Structured, Unstructured datasets and Time Series Data Rating: 0 out of 5 stars0 ratingsDeep Learning with Keras Rating: 5 out of 5 stars5/5Designing Machine Learning Systems with Python Rating: 0 out of 5 stars0 ratingsA Practical Approach for Machine Learning and Deep Learning Algorithms: Tools and Techniques Using MATLAB and Python Rating: 0 out of 5 stars0 ratingsRegression Analysis with Python Rating: 0 out of 5 stars0 ratingsPractical Full Stack Machine Learning: A Guide to Build Reliable, Reusable, and Production-Ready Full Stack ML Solutions Rating: 0 out of 5 stars0 ratingsHands-on ML Projects with OpenCV: Master computer vision and Machine Learning using OpenCV and Python Rating: 0 out of 5 stars0 ratingsPython Text Mining: Perform Text Processing, Word Embedding, Text Classification and Machine Translation Rating: 0 out of 5 stars0 ratingsPyTorch Recipes: A Problem-Solution Approach Rating: 0 out of 5 stars0 ratingsPython Machine Learning: A Step by Step Beginner’s Guide to Learn Machine Learning Using Python Rating: 0 out of 5 stars0 ratingsOperationalizing Machine Learning Pipelines: Building Reusable and Reproducible Machine Learning Pipelines Using MLOps Rating: 0 out of 5 stars0 ratingsData Analysis with Python: Introducing NumPy, Pandas, Matplotlib, and Essential Elements of Python Programming (English Edition) Rating: 0 out of 5 stars0 ratingsInterpretable AI: Building explainable machine learning systems Rating: 0 out of 5 stars0 ratingsHands-on Supervised Learning with Python Rating: 0 out of 5 stars0 ratings
Software Development & Engineering For You
PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Creative Selection: Inside Apple's Design Process During the Golden Age of Steve Jobs Rating: 5 out of 5 stars5/5Level Up! The Guide to Great Video Game Design Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsHand Lettering on the iPad with Procreate: Ideas and Lessons for Modern and Vintage Lettering Rating: 4 out of 5 stars4/5Managing Humans: Biting and Humorous Tales of a Software Engineering Manager Rating: 4 out of 5 stars4/5Beginning Programming For Dummies Rating: 4 out of 5 stars4/5Android App Development For Dummies Rating: 0 out of 5 stars0 ratingsPython For Dummies Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5Tiny Python Projects: Learn coding and testing with puzzles and games Rating: 4 out of 5 stars4/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5The Inmates Are Running the Asylum (Review and Analysis of Cooper's Book) Rating: 4 out of 5 stars4/5Lua Game Development Cookbook Rating: 0 out of 5 stars0 ratingsCoding with AI For Dummies Rating: 0 out of 5 stars0 ratingsiOS App Development For Dummies Rating: 0 out of 5 stars0 ratingsLearning Python Rating: 5 out of 5 stars5/5SQL For Dummies Rating: 0 out of 5 stars0 ratingsReversing: Secrets of Reverse Engineering Rating: 4 out of 5 stars4/5Succeeding with AI: How to make AI work for your business Rating: 0 out of 5 stars0 ratingsRy's Git Tutorial Rating: 0 out of 5 stars0 ratingsBlender 3D Printing Essentials Rating: 0 out of 5 stars0 ratingsAgile Practice Guide Rating: 4 out of 5 stars4/5iPhone Application Development For Dummies Rating: 4 out of 5 stars4/5Gray Hat Hacking the Ethical Hacker's Rating: 5 out of 5 stars5/5
Reviews for Time Series Forecasting using Deep Learning
0 ratings0 reviews
Book preview
Time Series Forecasting using Deep Learning - Ivan Gridin
CHAPTER 1
Time Series Problems and Challenges
Time series data are a very important source of information. People always tried to analyze time series data to understand the nature of events. Since ancient times, mankind has begun to wonder what lies in the essence of changes in moon cycles, weather, temperature, the river water level, harvest, and so on. And the essential way is to collect time series data of certain events and try to analyze them. Time series analysis gave a necessary tool for future prediction. These days, time series analysis is being used everywhere: from marketing and finance to education, healthcare, climate research, and robotics. There are many practical and theoretical approaches to time series forecasting: mathematics, statistics, random process theory, and so on. Artificial intelligence model-based forecasting has also become a popular research tool for the past decade. We start exploring how the latest advances in deep learning can be applied to time series forecasting.
Structure
In this chapter, we will discuss the following topics:
Introduction to time series analysis and time series forecasting
Time series characteristics
Common time series problems
Classical approaches
Promise of Deep Learning
Python for time series analysis
Objectives
In this chapter, we will make a short introduction to time series analysis. We will show some examples of time series problems and their importance. Also, we will examine the most famous classical methods for time series forecasting. And finally, we will get an explanation of the perspectives of the Deep Learning approach.
Introduction to time series analysis and time series forecasting
Time series is a sequence of observations that depends on time. Time is an essential feature in natural processes such as air temperature, a pulse of the heart, or stock price changes. Chronological order is an essential part of time series data that has to be present at the time of collecting the data. Time series analysis involves working with time-based data to make forecasts about the future. The period is measured in seconds, minutes, hours, days, months, years, or any other time unit.
Each time series dataset can be presented in tabular form, where the first column contains time data. Dataset is always sorted in chronological order. In the following table we show an example of a time series dataset:
London average temperature in 2020
Table 1.1: London average temperature monthly
Of course, formal mathematical models work only with data, but it is easier for humans to work with a visual representation of time series data, take a look in Figure 1.1:
Figure 1.1: London average temperature monthly
Although we rely on complex mathematical models for solving problems, we should not underestimate the human ability to find patterns and dependencies. Therefore, the visual representation of time series data is an important part of the analysis. We'll come back to this topic later.
There is some difference between time series analysis and time series forecasting. These two fields are tightly correlated, but they serve slightly different tasks.
Time series analysis
Time series analysis recognizes the essence of time series data structure and extracts helpful information from time series: trend, cyclic and seasonal deviations, correlations, and so on.
Time series analysis solves the following tasks:
Pre-process and perform feature extraction to get a meaningful and valid time series dataset.
Obtain definite insights into the historical time series dataset.
Data representation and visualization (graphical analysis, chart construction, report building)
Time series forecasting
Time series forecasting includes:
Developing models.
Using them to forecast future predictions.
Time series analysis is the first step to prepare and analyze time series dataset for time series forecasting.
Note: In this book, we will not stick to a strict definition of the term time series analysis
. We will also mean that the term time series analysis includes the problem of time series forecasting.
Time series characteristics
We have to understand how time series differ from one another. There are different types and classes of time series. Event short glance on time series graph can explain that the two processes that generated these datasets have a completely different nature.
Let us examine the time series sample in Figure 1.2:
Figure 1.2: Time Series 1
What does this graph resemble? Yes, of course, this time series dataset is a cardiogram. Such time series have the following properties:
Cycles
Fluctuations within a certain range of values
Ok, let us take a look to another one in Figure 1.3:
Figure 1.3: Time Series 2
Looking at Figure 1.3, it is already much more difficult to say what exactly this time series describes. This is the stock price of Facebook for the past 10 years, from 2011 to 2021. What can we say about this time series? This time series has the following characteristics:
Upward trend
Random fluctuations
Comparing figures 1.2 and 1.3, it is evident how different the nature of time series could be. In the next topic, we will mention the main time series types and characteristics.
Random walk
The random walk is the basic and one of the simplest time series models. A random walk is a sum of independent random variables with normal distribution: E1, E2, …EN. The following recurrence formula can describe the random walk process:
Rt+1 = Rt + Et
where t is the time or sequence index at which observations about the series have been taken.
It is easier to understand the nature of random walk exploring its generation ch1/random_walk.py:
Import part
import matplotlib.pyplot as plt
import random
Random walk generation
def generate_random_walk(length = 100, mu = 0, sig = 1):
ts = []
for i in range(length):
e = random.gauss(mu, sig)
if i == 0:
ts.append(e)
else:
ts.append(ts[i - 1] + e)
return ts
Example
if __name__ == '__main__':
random.seed(10)
random_walk = generate_random_walk(100)
plt.plot(random_walk)
plt.show()
Result
Figure 1.4: Random walk
The random walk is a fundamental stochastic process. It is an integral part of every natural time series. As we see later, each theoretical time series model assumes that it has some randomness, which is expressed as an addition of some random variable Et to each observation.
Later throughout the book, we will denote:
Et – random normal variable
Rt – random walk
Trend
Trend is the main global time series direction. A quick way to check the presence of a trend is to plot the time series. Let us examine the global climate change time series for the past 100 years in figure 1.5 (https://data.world/data-society/global-climate-change-data):
Figure 1.5: Global climate temperature
Time series shown in figure 1.5 has an apparent upward trend, which is presented as the red line.
The following formula describes a time series with a linear trend:
Tt = A + B···t + Et
Let us check the how time series with linear trend is generated ch1/trend_linear.py.
Import part
import matplotlib.pyplot as plt
import random
Example
if __name__ == '__main__':
random.seed(10)
length = 50
A = 5
B = .5
C = 3
trend = [A + B * i for i in range(length)]
noise = [C * random.gauss(0, 1) for _ in range(length)]
ts = [trend[i] + noise[i] for i in range(length)]
plt.plot(ts)
plt.plot(trend)
plt.show()
Result
Figure 1.6: Time series with linear trend
Time series do not always have a linear trend. Often this trend can be non-linear and can be expressed using the following formula:
Tt = A + Ft + Et
where Ft is non-linear monotonic function.
Below we provide an example of non-linear trend ch1/trend_nonlinear.py.
Import part
from math import log
import matplotlib.pyplot as plt
import random
Example
if __name__ == '__main__':
random.seed(1)
length = 100
A = 2
B = 25
C = 5
noise = [C * random.gauss(0, 1) for _ in range(length)]
trend = [A + B * log(i) for i in range(1, length + 1)]
ts = [trend[i] + noise[i] for i in range(length)]
plt.plot(ts)
plt.plot(trend)
plt.show()
Result
Figure 1.7: Time series with non-linear trend
Seasonality
Seasonality is repetitive variations in a time series dataset. Many processes are cyclic by their nature, and that is why these processes generate time series with the presence of seasonality. Figure 1.8 represents monthly pneumonia and influenza deaths per 10,000 people in the United States for 11 years, 1968–1978:
Figure 1.8: Pneumonia and influenza deaths per 10,000 people
In Figure 1.8, we can observe peaks each winter. And that is a rather obvious fact because during the winter, the spread of respiratory diseases increases. The same thing happens with time series, which represent temperatures, sales, water levels in rivers, and so on.
A periodic function is a function that repeats its values at regular intervals:
St+p = St
The most common mathematical periodic functions are trigonometric functions: sin(x), cos(x).
So the formula below describes a time series with seasonality:
Tt = A + Bt + CSt + Et
The construction of time series with seasonality can be better understood by an example ch1/seasonality.py.
Import part
from math import