Time Series Forecasting using LSTM and Transformer This repository presents a comparative study of time series forecasting using Long Short-Term Memory (LSTM) networks and Transformer-based architectures. The project focuses on predicting sequential numerical data (e.g., stock prices) and evaluating the strengths and limitations of each model.
π Project Overview
Time series forecasting is a critical task in finance, economics, and operations. Traditional RNN-based models like LSTM handle sequential dependencies well, while Transformer models leverage self-attention to capture long-range temporal patterns more effectively.
This project: Implements LSTM and Transformer models from scratch Trains both models on the same dataset Compares their performance using standard regression metrics Demonstrates practical trade-offs in accuracy, training time, and scalability
π§ Models Implemented
- LSTM (Long Short-Term Memory) Captures temporal dependencies using gated recurrent units Effective for small-to-medium time horizons Sequential processing (slower on large datasets)
- Transformer Uses self-attention instead of recurrence Handles long-range dependencies efficiently Parallelizable and scalable for large datasets π Repository Structure βββ time_series_code.ipynb # Main notebook with data preprocessing, training, and evaluation βββ README.md # Project documentation βββ requirements.txt # Python dependencies (optional) βββ data/ # Dataset (if applicable)
βοΈ Installation & Setup Clone the repository: git clone https://github.com/your-username/time-series-forecasting.git cd time-series-forecasting (Optional) Create a virtual environment: python -m venv venv source venv/bin/activate Install dependencies: pip install -r requirements.txt Open the notebook: jupyter notebook time_series_code.ipynb
π§ͺ Experiment Pipeline Data loading and cleaning Feature scaling and windowing Trainβtest split Model training (LSTM & Transformer) Prediction and visualization Performance evaluation π Evaluation Metrics Mean Absolute Error (MAE) Mean Squared Error (MSE) Root Mean Squared Error (RMSE) π Results Summary Model Strengths Limitations LSTM Stable, interpretable, good for short trends Slower training, limited long-term memory Transformer Captures long-term patterns, scalable Higher computational cost (Exact numerical results are available in the notebook.) π οΈ Technologies Used Python NumPy, Pandas TensorFlow / PyTorch Scikit-learn Matplotlib / Seaborn Jupyter Notebook π― Key Learnings Transformers outperform LSTMs on longer sequences Attention mechanisms reduce information loss Data preprocessing significantly impacts forecasting accuracy
π€ Author Rushikesh Iname π Bengaluru, India πΌ Data & AI Engineer