Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamfarrokhnejad/stock-forecasting-rnn
LSTM vs GRU
https://github.com/iamfarrokhnejad/stock-forecasting-rnn
deep-learning-algorithms deep-neural-networks deeplearning gated-neural-network gated-recurrent-unit gated-recurrent-units gru lstm lstm-model lstm-neural-networks neural-network neural-networks neuralnetwork neuralnetworks python pytorch time-series
Last synced: 4 days ago
JSON representation
LSTM vs GRU
- Host: GitHub
- URL: https://github.com/iamfarrokhnejad/stock-forecasting-rnn
- Owner: IAmFarrokhnejad
- License: mit
- Created: 2025-01-17T15:56:19.000Z (9 days ago)
- Default Branch: main
- Last Pushed: 2025-01-17T16:09:05.000Z (9 days ago)
- Last Synced: 2025-01-17T17:24:10.908Z (9 days ago)
- Topics: deep-learning-algorithms, deep-neural-networks, deeplearning, gated-neural-network, gated-recurrent-unit, gated-recurrent-units, gru, lstm, lstm-model, lstm-neural-networks, neural-network, neural-networks, neuralnetwork, neuralnetworks, python, pytorch, time-series
- Language: Python
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Time Series Forecasting with LSTM and GRU Models
This repository contains Python code for time series forecasting using Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) neural networks implemented in PyTorch. The models are trained and evaluated on a dataset named `amazon.csv`. (provided in this repository)
## Features
- **Model Architectures:** Includes LSTM and GRU implementations for sequence modeling.
- **Data Preprocessing:** Time series data is prepared with scaling, sequence generation, and train-validation splitting.
- **Model Training:** Comprehensive training loop with loss computation and model validation.
- **Performance Metrics:** Training and validation loss are reported for each epoch to track model performance.## Requirements
- Python 3.8 or later
- PyTorch 2.0 or later
- NumPy
- Matplotlib
- scikit-learnInstall the required libraries using:
```bash
pip install torch numpy matplotlib scikit-learn
```### Hardware
- A CUDA-compatible GPU is recommended for efficient training.---
## Setup Instructions
1. **Clone the Repository**:
```bash
git clone https://github.com/IAmFarrokhnejad/Stock-Forecasting-RNN
```2. **Install Dependencies**:
```bash
pip install torch torchvision matplotlib seaborn scikit-learn
```3. **Prepare Your Dataset**:
- Ensure the amazon.csv file is placed in the root directory. The file should contain a single time series column for analysis.
- In case of changing the data directory, update the data variable path in the script to point to your dataset path.## Running the Code
Execute the script to train both the LSTM and GRU models:
```bash
python stock-forecasting.py
```The script will:
1. Train and validate models sequentially for EfficientNet, MobileNetV2, and ShuffleNet.
2. Save the classification report and confusion matrix for each model in the specified directory.---
## Results
The models were trained for 40 epochs, and the following trends were observed:
1. LSTM:
- Training Loss decreased to 0.0001 by epoch 40.
- Validation Loss stabilized at 0.0016.2. GRU:
- Training Loss decreased to 0.0001 by epoch 40.
- Validation Loss stabilized at 0.0019.Both models demonstrate strong convergence, with GRU showing slightly slower validation loss improvement compared to LSTM.
---
## License
This project is licensed under the [MIT License](LICENSE).
---
## Author
[Morteza Farrokhnejad](https://github.com/IAmFarrokhnejad)
---
## Acknowledgments
- [PyTorch](https://pytorch.org/) for the deep learning framework.
- Matplotlib for visualization.