Skip to content

aviralb13/ML_FINAL_PROJECT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Price Prediction Using Machine Learning

Final Project — ML & Data Science

A full-stack web application that fetches live stock data and runs 8 ML models to predict 7-day price forecasts with full evaluation metrics and visualizations.


Models Included

# Model Type Library
1 Linear Regression Baseline linear scikit-learn
2 Ridge Regression L2-regularized linear scikit-learn
3 SVR (RBF kernel) Support Vector Machine scikit-learn
4 Random Forest Ensemble (300 trees) scikit-learn
5 Gradient Boosting Boosted ensemble scikit-learn
6 XGBoost Extreme gradient boost xgboost
7 LightGBM Fast gradient boosting lightgbm
8 LSTM (Sequence) Sequence neural net numpy

XGBoost and LightGBM are the top performers for financial time series.


Features Engineered (32 features)

  • Moving Averages: MA-5, MA-10, MA-20, MA-50
  • EMA-12, EMA-26, MACD, MACD Signal, MACD Histogram
  • RSI (14-period)
  • ROC-5, ROC-10, Momentum-5
  • Bollinger Bands: Upper, Lower, Width, %B
  • Volatility (10-day rolling std)
  • Price Change %, High-Low %, Close-Open %
  • Volume MA, Volume Ratio
  • Lag features: Close t-1, t-2, t-3, t-5

Evaluation Metrics

  • MSE — Mean Squared Error
  • RMSE — Root Mean Squared Error
  • — Coefficient of Determination (fit quality)
  • MAE — Mean Absolute Error

Visualizations

  1. 60-day historical price + all 8 model forecasts overlaid
  2. 7-day forecast bar chart (best model)
  3. Full prediction table (all models × 7 days)
  4. Model cards with full metric breakdown
  5. R² horizontal bar chart (all models)
  6. MSE & RMSE grouped bar chart
  7. Test accuracy % bar chart

Setup & Run Instructions

Prerequisites

  • Python 3.9 or higher
  • Internet connection (for live Yahoo Finance data)

Step 1 — Unzip the project

cd Downloads
unzip stock_ml_predictor.zip
cd stock_ml_predictor

Step 2 — Create a virtual environment

python -m venv venv

Step 3 — Activate the virtual environment

Windows:

venv\Scripts\activate

Mac / Linux:

source venv/bin/activate

Step 4 — Install all dependencies

pip install -r requirements.txt

This installs Flask, yfinance, scikit-learn, XGBoost, LightGBM, pandas, numpy.

Step 5 — Run the app

python app.py

You'll see output like:

🚀  Stock ML Predictor  →  http://localhost:5000

   XGBoost  : ✓
   LightGBM : ✓

Step 6 — Open browser

http://localhost:5000

Usage

  1. Enter any stock ticker (AAPL, TSLA, NVDA, AMZN, SPY, etc.)
  2. Click Analyze → or press Enter
  3. Wait ~20–40 seconds for training 8 models on 2 years of live data
  4. Explore all predictions, charts, and model evaluations

Project Structure

stock_ml_predictor/
├── app.py                   ← Flask backend + all 8 ML models
├── requirements.txt         ← Python dependencies
├── README.md
├── templates/
│   └── index.html           ← Main HTML page
└── static/
    ├── css/
    │   └── style.css        ← Dark theme UI
    └── js/
        └── main.js          ← Charts (Chart.js) + frontend logic

Data Source

Live OHLCV data from Yahoo Finance via yfinance — 2 years of daily data.


Final Project — Machine Learning & Data Science

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors