This project is a web application that uses a Convolutional Neural Network (CNN) to predict stock price movements (Up, Down, or Flat) based on uploaded stock chart images. The application is built using Streamlit and TensorFlow/Keras, with a Jupyter Notebook (stock_prediction_app.ipynb) containing the implementation.
- Upload stock chart images (JPG, PNG, JPEG) for analysis.
- Predict stock price movement (Up, Down, or Flat) using a pre-trained CNN model.
- Display training and test accuracy of the model.
- Visualize the distribution of predicted classes for test data using a histogram.
- Python 3.8+
- Streamlit
- TensorFlow
- Keras
- NumPy
- Matplotlib
- Scikit-learn
- Jupyter Notebook (optional, for running the notebook directly)
- Clone the repository:
git clone <repository_url> cd <repository_directory>
- Install the required packages:
pip install -r requirements.txt
- Ensure you have a dataset of stock chart images or modify the
load_real_datafunction to load your own dataset.
- Run the Streamlit app:
Note: You may need to convert the Jupyter Notebook (
streamlit run stock_prediction_app.py
stock_prediction_app.ipynb) to a Python script (stock_prediction_app.py) using a tool likejupytextor by manually copying the code into a.pyfile. - Open the provided URL in your browser (typically
http://localhost:8501). - Upload a stock chart image to predict the stock movement (Up, Down, or Flat).
- View the prediction and the class distribution histogram for test data.
stock_prediction_app.ipynb: Jupyter Notebook containing the main application code.requirements.txt: List of required Python packages.temp_image.png: Temporary file created when uploading an image (generated at runtime).
- Architecture: The CNN model consists of three convolutional layers with ReLU activation, each followed by max-pooling, a flatten layer, a dense layer with 256 units, a dropout layer (0.5), and a final dense layer with softmax activation for three classes (Up, Down, Flat).
- Input: Images are resized to 224x224 pixels and normalized to [0, 1].
- Training: The model is trained on a dummy dataset (replace with real stock chart images). It uses the Adam optimizer and categorical cross-entropy loss.
- Output: Predictions are classified into three categories: Up (0), Down (1), or Flat (2).
- The
load_real_datafunction currently generates random data for demonstration. Replace it with a function to load actual stock chart images and corresponding labels. - Ensure the uploaded images are valid stock charts for accurate predictions.
- The model is trained for 10 epochs with a batch size of 32. Adjust these parameters as needed for your dataset.
- The application saves uploaded images temporarily as
temp_image.png. Ensure write permissions in the working directory. - To run the notebook directly, use Jupyter Notebook or Jupyter Lab. To run as a Streamlit app, convert to a
.pyfile.