Multivariate LSTM
Missing Values
Time Series Forecasting
Machine Learning
Deep Learning

Multivariate LSTM with missing values

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Multivariate LSTM (Long Short-Term Memory) models are a powerful extension of recurrent neural networks (RNNs) particularly suited to time series forecasting tasks where multiple features with complex interrelationships have to be considered. These models accommodate the temporal dependencies inherent in sequential data, capturing both short- and long-term patterns effectively. In real-world applications, however, datasets often contain missing values, complicating the modeling process. The challenge is to handle these gaps without losing important temporal dynamics.

Understanding LSTM Networks

Basics of LSTM

LSTM, a type of RNN, is specifically designed to avoid the long-term dependency problem faced by standard RNNs. An LSTM cell consists of three main gates: the input gate, the forget gate, and the output gate, which control the flow of information through the cell state:

Forget Gate: Decides what information should be discarded from the cell state by using a sigmoid function.

f_t=σ(W_f[h_t1,x_t]+b_f)f\_t = \sigma(W\_f \cdot [h\_{t-1}, x\_t] + b\_f)

Input Gate: Determines what new information will be stored in the cell state.

i_t=σ(W_i[h_t1,x_t]+b_i)i\_t = \sigma(W\_i \cdot [h\_{t-1}, x\_t] + b\_i)

Then, a new candidate value for the cell state is created:

C~t=tanh(W_C[ht1,x_t]+b_C)\tilde{C}*t = \tanh(W\_C \cdot [h*{t-1}, x\_t] + b\_C)

Output Gate: Decides the next hidden state, balancing between the input and the memory of the network.

o_t=σ(W_o[h_t1,x_t]+b_o)o\_t = \sigma(W\_o \cdot [h\_{t-1}, x\_t] + b\_o)

The cell state is updated as follows:

C_t=f_tC_t1+i_tC~_tC\_t = f\_t \cdot C\_{t-1} + i\_t \cdot \tilde{C}\_t

Finally, the hidden state output is updated:

h_t=o_ttanh(C_t)h\_t = o\_t \cdot \tanh(C\_t)

Multivariate Time Series and LSTM

In multivariate time series, each time step involves multiple variables (features), all of which contribute to the prediction. LSTM networks are apt for handling these because they can process input sequences of varying lengths and multivariate inputs within a coherent framework.

Handling Missing Values

Common Causes of Missing Data

Sensor Failures: Data from sensors is prone to missing due to malfunction or environmental interference. • Data Entry Errors: Manual data entries may be incomplete due to human oversight. • Transmission Losses: Data can be lost in transmission between collection points and storage systems.

Techniques to Manage Missing Values

Deletion: Removal of missing data instances is straightforward but can lead to significant data loss, especially in high-dimensional spaces.

Imputation: More sophisticated techniques include imputing missing values using domain knowledge, statistical methods, or predictions based on observed data: • Mean/Median/Mode Imputation: Simple and effective for small amounts of missing data but may skew distributions. • Interpolation: Utilizes surrounding data to estimate missing values; effective for time series. • K-Nearest Neighbors (KNN): Predicts missing values using the most similar, fully observed data points. • Machine Learning Models for Imputation: Algorithms such as Random Forests or other specialized models can predict missing values using available features.

Model-Based Imputation: Leveraging advanced models like LSTM for imputing missing data offers the ability to preserve temporal dependencies. An iterative process can be employed whereby missing values are initialized (e.g., using mean), then refined iteratively through prediction.

Incorporating Imputation into LSTM Models

Once missing values are imputed, the enriched dataset can be used to train the LSTM model to predict future time sequences accurately. Error propagation due to imputation must be managed carefully, ensuring that the model accounts for any imputation bias.

A Case Study Example

Consider a multivariate time series forecasting task for sensor data in an industrial setting, where each sensor records temperature, pressure, humidity, etc. Once prepared, the dataset is subject to the missing data imputation phase. For illustration:

  1. Data Collection and Preprocessing: Collect sensor readings and handle outliers or erroneous measurements.
  2. Imputation: Use KNN imputation to fill in gaps left by malfunctioning sensors. Initial imputation might use simple methods for large gaps with KNN refining this in multiple iterations.
  3. LSTM Configuration: Configure an LSTM network with layers suitable for capturing the temporal dependencies of such multivariate data. Tune hyperparameters to avoid overfitting.
  4. Training: Properly train the LSTM network on the imputed dataset.
  5. Validation and Testing: Evaluate the network on unseen data, ensuring it generalizes well. Use performance metrics like RMSE (Root Mean Square Error) and MAE (Mean Absolute Error).

Summary Table of Key Points

AspectDetails
LSTM ComponentsForget gate, Input gate, Output gate, Cell State
Handling Missing DataDeletion, Imputation (Mean, Median, Mode, KNN, Interpolation, Machine Learning-based)
Imputation and LSTM InteractionInitial imputation with refinements, balancing bias and variance
Technical MeasuresRMSE, MAE for performance evaluation, Hyperparameter tuning for LSTM
Best PracticesIterative imputation, leveraging domain knowledge, appropriate model selection
Real-world ApplicationSensor data in industrial settings for monitoring and forecasting tasks involving reliable data

Challenges and Future Directions

Handling missing data in multivariate time series remains a challenging area of research. Incorporating domain-specific knowledge and exploring hybrid models combining LSTM with other machine learning techniques could yield improved results. Furthermore, integrating robust techniques to address data imputation's innate uncertainty is crucial for advancing this field. Looking ahead, developments in deep learning and nonlinear time series methodologies continue to offer promising directions for managing missing data effectively.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.