A Streamlit-based web application that predicts stock prices using a Long Short-Term Memory (LSTM) neural network. Users can upload historical stock price data, tune model hyperparameters interactively, train the model, and visualize actual vs predicted prices along with performance metrics.
- Overview
- Architecture
- Pipeline
- Features
- Tech Stack
- Requirements
- Installation
- How to Run
- Usage Guide
- Model Architecture
- Evaluation Metrics
- Important Notes
- Future Enhancements
- License
This application demonstrates how LSTM-based deep learning models can be applied to time-series forecasting in finance. It allows end users to:
- Upload custom stock datasets
- Experiment with different hyperparameters
- Train an LSTM model in real time
- Visualize predictions and training performance
-
📂 CSV Upload – Upload historical stock price datasets
-
👀 Data Preview – Inspect uploaded data before training
-
🎛 Dynamic Hyperparameter Tuning
- Sequence length (look-back window)
- Epochs
- Batch size
- LSTM units (Layer 1 & 2)
- Train–test split ratio
-
🚀 One-click Model Training
-
📉 Training Loss Visualization
-
📊 Performance Metrics – Mean Squared Error (MSE)
-
📈 Interactive Prediction Plot – Actual vs Predicted prices
- Frontend: Streamlit
- Backend / ML: TensorFlow, Keras (LSTM)
- Data Processing: NumPy, Pandas
- Visualization: Matplotlib
- Preprocessing: Scikit-learn (MinMaxScaler)
-
Python 3.8+
-
Libraries:
streamlit numpy pandas matplotlib scikit-learn tensorflow
pip install streamlit numpy pandas matplotlib scikit-learn tensorflow-
Save the Application
app.py
-
Prepare CSV Data Your dataset must contain a
Closecolumn.Example format:
Date,Open,High,Low,Close,Volume 2023-01-01,100.0,102.5,99.5,101.0,100000 2023-01-02,101.5,103.0,100.0,102.0,120000
-
Run the App
streamlit run app.py
-
Access the Application
http://localhost:8501
-
Upload CSV via the file uploader
-
Verify Data Preview (ensure
Closecolumn exists) -
Configure Hyperparameters using sidebar sliders:
- Look-back window
- Epochs
- Batch size
- LSTM units
- Train–test split
-
Train Model using the Train Model button
-
Analyze Results:
- Training loss curve
- Mean Squared Error (MSE)
- Actual vs Predicted stock price graph
The model is built using Keras Sequential API:
-
MinMaxScaler Normalizes prices between 0 and 1
-
Sequence Generator (
create_sequences) Converts time series data into LSTM-ready sequences -
LSTM Layer 1
LSTM(units=lstm_units_1, return_sequences=True)
-
LSTM Layer 2
LSTM(units=lstm_units_2)
-
Dense Output Layer
Dense(1)
-
Optimizer: Adam
-
Loss Function: Mean Squared Error
- Mean Squared Error (MSE) Measures average squared difference between actual and predicted prices
-
🚨 For educational purposes only
-
📉 Stock market prediction is highly volatile and uncertain
-
📊 Model performance depends heavily on:
- Data quality
- Data size
- Hyperparameter choices
-
❌ Not intended for financial or investment advice
- Add technical indicators (RSI, MACD, EMA)
- Support multi-stock prediction
- Integrate real-time data via APIs
- Deploy as a cloud-based API (GCP / AWS)
- Add model comparison (LSTM vs GRU vs Transformer)
This project is licensed under the MIT License.

