https://github.com/walmartbaggg/Stock-Prediction
Machine learning project using LSTM networks to predict stock prices based on historical data from multiple companies.
https://github.com/walmartbaggg/Stock-Prediction
machine-learning ml prediction predictions python stock stock-market stock-prediction stock-price-prediction stock-prices tensorflow yfinance
Last synced: 6 months ago
JSON representation
Machine learning project using LSTM networks to predict stock prices based on historical data from multiple companies.
- Host: GitHub
- URL: https://github.com/walmartbaggg/Stock-Prediction
- Owner: m626zNq
- License: gpl-3.0
- Created: 2024-10-19T20:03:10.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T04:51:27.000Z (12 months ago)
- Last Synced: 2024-11-05T02:04:35.484Z (11 months ago)
- Topics: machine-learning, ml, prediction, predictions, python, stock, stock-market, stock-prediction, stock-price-prediction, stock-prices, tensorflow, yfinance
- Language: Python
- Homepage:
- Size: 1.45 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stock Price Prediction with Machine Learning
This project uses machine learning to predict stock prices based on historical data. It employs a Long Short-Term Memory (LSTM) neural network model to forecast future stock prices for various companies.
## Features
- Data collection from Yahoo Finance using the `yfinance` library
- LSTM model for time series prediction
- Training on multiple stock data to improve generalization
- Prediction visualization with matplotlib
- GPU support for faster training (if available)## Requirements
- Python 3.7+
- TensorFlow 2.x
- yfinance
- pandas
- numpy
- matplotlib
- scikit-learnYou can install the required packages using:
```
pip install -r requirements.txt
```## Usage
### Training the Model
***The weights are already trained and saved in the repo 'weights' folder for the current version. This is optional.***To train the model on historical stock data:
```
python scripts/train.py
```This script will:
1. Download historical stock data for predefined tickers
2. Prepare the data for training
3. Build and train the LSTM model
4. Save the trained model as `model.h5` and the scaler as `scaler.npy`### Making Predictions
To make predictions using the trained model:
```
python scripts/inference.py --stock --output --epoch
```By default, this will predict stock prices for NVIDIA (NVDA) and save the plot as `predictions.png`. You can modify the ticker and output filename by passing the appropriate arguments as shown above.
## How it Works
1. **Data Collection**: Historical stock data is fetched using the `yfinance` library.
2. **Data Preprocessing**: The data is scaled using MinMaxScaler to normalize the values.
3. **Model Architecture**: An LSTM-based neural network is used for sequence prediction.
4. **Training**: The model is trained on multiple stock data to capture general market trends.
5. **Prediction**: The trained model predicts future stock prices based on recent data.
6. **Visualization**: Predictions are plotted against actual prices, including a simple trading recommendation.## Customization
- To train on different stocks, update the list of tickers in `train.py`.
- Adjust the `time_step` and `future_days` parameters in both scripts to change the input sequence length and prediction horizon.## License
This project is released under the GPL-3.0. For more information, see the [LICENSE](LICENSE) file.
## Disclaimer
This may provide inaccurate predictions. Dont rely on it too much until it is improved.