...
/Preparing and Analyzing Time Series Data with LSTM Models
Preparing and Analyzing Time Series Data with LSTM Models
Discover how to prepare and analyze time series data with LSTMs, from importing libraries to data temporalization and scaling.
We'll cover the following...
In this lesson, we explore time series analysis using Long Short-Term Memory (LSTM) models. We begin by importing necessary libraries, including TensorFlow for LSTM functionalities and user-defined libraries for data preprocessing and visualization. Our primary focus is on temporalizing the data, a crucial step for LSTM modeling. We’ll explore the significance of temporalization and proceed to split and scale the data, setting the foundation for building robust time series models.
Imports and data
We get started with importing the libraries. LSTM related classes are taken from the TensorFlow library. Also, the user-defined libraries, e.g., datapreprocessing, performancemetrics, and simpleplots, are imported.
- Lines 33–34: We set the value for two constants. We set
SEEDto123, which will be used as the seed for random number generation, andDATA_SPLIT_PCTto0.2, indicating a 20% data split for train-test separation. - Lines 36–38: We import
rcParamsfrom Matplotlib’spylabmodule. We set the default figure size for plots to8by6inches and update the font size for Matplotlib plots. - Lines 40–42: We print informative messages about the data split percentage, random generator seeds, and the size of figures that will be plotted later in the code. This provides insights into the settings being used in the script.
Next, the data is read, and the basic preprocessing steps are performed.
Temporalizing the data
From an LSTM modeling standpoint, a usual two-dimensional input, also referred to as planar data, doesn’t directly provide time windows. However, the time windows are required to extract spatio-temporal patterns. Therefore, the planar data is temporalized. In temporalization, a time window spanning observations in ...