This project demonstrates the use of a Long Short-Term Memory (LSTM) neural network, a type of Recurrent Neural Network (RNN), to forecast future stock prices based on historical data. The model is built with TensorFlow and Keras and trained on historical stock data fetched from Yahoo Finance.
The script follows a standard machine learning workflow for time series forecasting:
yfinance library.MinMaxScaler from Scikit-learn. This normalization is crucial for neural network performance.1. Navigate to the project directory:
cd stock-price-prediction-lstm
2. Install dependencies from the requirements file:
pip install -r requirements.txt
3. Run the Python script (ensure your script name matches):
python stock_predictor.py
The script will fetch the latest data, train the model, and output its evaluation metric.
The script will print the model's performance to the console:
Fetching data for AAPL from 2012-01-01 to 2024-01-01...
Data fetched successfully.
Starting model training...
Epoch 1/25
...
Epoch 25/25
Model training complete.
Calculating model performance...
Root Mean Squared Error (RMSE): 4.52
Additionally, the script will generate and save a plot (e.g., prediction_vs_actual.png) that visually compares the actual stock prices with the prices predicted by the LSTM model.