This project demonstrates how to build a Long Short-Term Memory (LSTM) model using Keras to predict Tesla's stock closing prices based on historical data.
Tags: deep-learning lstm stock-prediction time-series-analysis tensorflow keras tesla tsla yahoo-finance machine-learning python numpy pandas matplotlib minmaxscaler price-forecasting sequential-mod
The main objective is to:
- Load historical Tesla stock price data
- Preprocess and normalize the data
- Create time-series sequences for the LSTM model
- Train the LSTM neural network
- Predict and visualize future stock prices
- Dataset used:
TSLA.csv
- Source: Yahoo Finance
- Important feature:
Close
price of the stock - The
Date
column is set as the index for time series analysis
- Model: Sequential
- Layers:
- LSTM layer with 50 units
- Dense layer with 1 output
- Loss function: Mean Squared Error (MSE)
- Optimizer: Adam
- Epochs: 100
- Batch size: 32
- Load and parse the
Date
column - Extract only the
Close
prices - Apply MinMaxScaler to scale the data between 0 and 1
- Create sequences of
60
days to predict the61st
day price - Split the dataset into 80% training and 20% testing
Training Accuracy: Achieved low loss values indicating good learning
Predictions: Accurately predicted trends and closing prices
Visualization: Plotted predicted vs actual prices for clear comparison