Nothing Special   »   [go: up one dir, main page]

Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions
Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions
Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions
Ebook623 pages2 hours

Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions

Rating: 0 out of 5 stars

()

Read preview

About this ebook

This book is amid at teaching the readers how to apply the deep learning techniques to the time series forecasting challenges and how to build prediction models using PyTorch.

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.
LanguageEnglish
Release dateOct 15, 2021
ISBN9789391392659
Time Series Forecasting using Deep Learning: Combining PyTorch, RNN, TCN, and Deep Neural Network Models to Provide Production-Ready Prediction Solutions

Read more from Ivan Gridin

Related to Time Series Forecasting using Deep Learning

Related ebooks

Software Development & Engineering For You

View More

Related articles

Reviews for Time Series Forecasting using Deep Learning

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    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

    Enjoying the preview?
    Page 1 of 1