-
-
Notifications
You must be signed in to change notification settings - Fork 339
Add-LSTM #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add-LSTM #247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive implementation of Long Short-Term Memory (LSTM) neural networks for time series forecasting in R, providing a complete workflow from data preprocessing to prediction visualization.
- Implements LSTM model architecture with configurable parameters for time series prediction
- Provides comprehensive data preprocessing including normalization and sequence generation
- Includes evaluation metrics, visualization capabilities, and multi-step ahead prediction functionality
# Reshape for ggplot | ||
plot_data_long <- reshape2::melt(plot_data, id.vars = "Index") |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reshape2 package is used without being explicitly loaded or checked for availability. Consider using tidyr::pivot_longer() as a more modern alternative, or add a requireNamespace check for reshape2.
Copilot uses AI. Check for mistakes.
indices <- sample(1:dim(X)[1]) | ||
|
||
train_indices <- indices[1:train_size] | ||
test_indices <- indices[(train_size + 1):length(indices)] | ||
|
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random sampling for train/test split breaks the temporal order of time series data. For time series, use sequential split to maintain temporal relationships: train_indices <- 1:train_size and test_indices <- (train_size + 1):dim(X)[1].
indices <- sample(1:dim(X)[1]) | |
train_indices <- indices[1:train_size] | |
test_indices <- indices[(train_size + 1):length(indices)] | |
train_indices <- 1:train_size | |
test_indices <- (train_size + 1):dim(X)[1] |
Copilot uses AI. Check for mistakes.
|
||
# Create plot | ||
p <- ggplot(plot_data_long, aes(x = Index, y = value, color = variable)) + | ||
geom_line(size = 1) + |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'size' aesthetic is deprecated in ggplot2. Use 'linewidth' instead for line geometries.
geom_line(size = 1) + | |
geom_line(linewidth = 1) + |
Copilot uses AI. Check for mistakes.
PR: LSTM Time Series Forecasting in R
This PR introduces a fully documented implementation of a Long Short-Term Memory (LSTM) neural network in R for time series prediction and forecasting.
The implementation leverages the
keras
andtensorflow
packages to build, train, and evaluate LSTM models capable of learning temporal dependencies in sequential data.Overview
The provided LSTM workflow covers:
Data Preprocessing:
Model Architecture:
Training and Evaluation:
Prediction Capabilities:
ggplot2
Best Practices:
This LSTM implementation is suitable for:
Complexity
The approach demonstrates how LSTMs can model sequential dependencies more effectively than traditional regression or moving-average methods.