Predict the GLD (Gold ETF) closing price in real time - powered by Machine Learning
11 global market indicators Β Β·Β 7 years of daily trading data Β Β·Β RΒ² β 99.8%
- π Overview
- π Live Demo
- β¨ Features
- π οΈ Tech Stack
- π§ How It Works
- π Model Performance
- π Dataset Overview
- ποΈ Project Structure
- βοΈ Getting Started
- π Usage
- Notebook
- π EDA Highlights
- π€ Contributing
- π License
This project builds a complete end-to-end machine learning pipeline to predict the price of the GLD ETF (Gold Exchange-Traded Fund) based on correlated global market indicators.
The workflow covers:
- Exploratory Data Analysis (EDA) - distributions, trends, outlier detection, and correlation analysis
- Model Training & Comparison - Linear Regression, Decision Tree, Random Forest, and KNN evaluated head-to-head
- Model Selection - KNN (k=2) selected via elbow-curve analysis for the lowest error
- Web Application - Interactive Flask app where users enter market values and get an instant GLD price prediction
Run locally following the Getting Started steps below.
| Route | Page | Description |
|---|---|---|
/ |
Home | Project overview, dataset statistics & live model metrics |
/predict |
Predict | Enter 11 market values β get instant GLD price estimate |
/about |
About | Dataset info, model details & feature breakdown |
| Enter 11 market indicators and receive an instant GLD price estimate - no page reload needed. |
KNN Regressor tuned to k=2 via elbow-curve analysis achieves RΒ² β 0.998.
|
| Modern UI built with Inter typography, Font Awesome icons, and a clean gold-accented palette. | Jupyter notebook with exploratory analysis, feature correlations, and model comparison. |
| Layer | Technology |
|---|---|
| Backend | Python 3.8+, Flask 2.3+ |
| ML / Data | scikit-learn, Pandas, NumPy |
| Frontend | HTML5, CSS3, Vanilla JS |
| Fonts & Icons | Google Fonts (Inter), Font Awesome 6 |
| ML Algorithm | K-Nearest Neighbours Regressor |
| Deployment | Gunicorn (production WSGI) |
Market Inputs βββΊ StandardScaler βββΊ KNN Regressor (k=2) βββΊ GLD Price
(11 features) (fitted on (80/20 split, (USD)
train set) RΒ² β 0.998)
- Data - 1,718 daily rows of global market data (Jan 2011 β Dec 2018) loaded from
FINAL_USO.csv. - Preprocessing - Features scaled with
StandardScalerfitted only on the training set to prevent data leakage. - Model Selection - Elbow-curve plotted for
k = 1to20;k = 2minimises error without overfitting. - Prediction - User inputs are scaled with the same scaler, then passed to the trained KNN model for an instant result.
All models trained on 80% of the data and evaluated on the remaining 20% (random_state=0).
| Model | RΒ² | MAE | RMSE |
|---|---|---|---|
| π₯ KNN (k=2) β selected | 0.9983 | $0.59 | $1.10 |
| Random Forest | 0.9961 | $0.78 | $1.41 |
| Decision Tree | 0.9934 | $0.91 | $1.83 |
| Multiple Linear Regression | 0.9612 | $2.44 | $4.45 |
| Simple Linear Regression | 0.8741 | $4.37 | $8.01 |
KNN with k=2 was selected as the best model based on elbow-curve analysis (k=1 to 20).
It explains 99.83% of variance in GLD closing prices on completely unseen test data.
| Property | Detail |
|---|---|
| Source | Kaggle - Gold Price Prediction Dataset |
| Source file | Dataset/FINAL_USO.csv |
| Records | 1,718 daily rows |
| Date Range | January 2011 β December 2018 |
| Total Columns | 81 |
| Features Used | 11 |
| Target Column | Close - GLD ETF daily closing price (USD) |
| Missing Values | β None |
| Duplicates | β None |
Click to expand feature descriptions
| # | Feature | Description | Correlation w/ GLD |
|---|---|---|---|
| 1 | SP_close |
S&P 500 Index - daily closing value | +0.63 |
| 2 | DJ_close |
Dow Jones Industrial Average - daily close | +0.61 |
| 3 | EU_Price |
EUR / USD exchange rate | -0.51 |
| 4 | OF_Price |
Crude Oil Futures price (USD / barrel) | +0.29 |
| 5 | SF_Price |
Silver Futures price | +0.87 |
| 6 | PLT_Price |
Platinum Futures price | +0.55 |
| 7 | PLD_Price |
Palladium Futures price | +0.38 |
| 8 | USDI_Price |
US Dollar Index | -0.74 |
| 9 | GDX_Close |
VanEck Gold Miners ETF - daily close | +0.92 |
| 10 | USO_Close |
United States Oil Fund ETF - daily close | -0.19 |
| 11 | RHO_PRICE |
Rhodium spot price | +0.41 |
Gold_Price_Prediction/
β
βββ π app.py β Flask app, model training & API routes
βββ π requirements.txt β Python dependencies
βββ π Gold_predict.ipynb β EDA, model comparison, elbow-curve analysis
β
βββ π Dataset/
β βββ FINAL_USO.csv β Historical market data (2011β2018)
β
βββ π templates/
β βββ index.html β Home - stats dashboard
β βββ predict.html β Prediction form with live results
β βββ about.html β Methodology & feature breakdown
β
βββ π static/
βββ style.css β Global stylesheet (gold-accented theme)
- Python 3.8+
- pip
git clone https://github.com/anubhab1601/Gold_Price_Prediction.git
cd Gold_Price_Prediction# Create
python -m venv venv
# Activate - Windows
venv\Scripts\activate
# Activate - macOS / Linux
source venv/bin/activatepip install -r requirements.txtpython app.pyOpen http://127.0.0.1:5001 in your browser. π
Navigate to http://127.0.0.1:5001/predict, fill in the 11 market indicator fields, and click Predict.
jupyter notebook Gold_predict.ipynbGold_predict.ipynb walks through the full ML pipeline:
| Section | Content |
|---|---|
| EDA | Distributions, box plots, correlation heatmap, pairplot, outlier analysis |
| Feature Engineering | Selection of the 11 most predictive market indicators |
| Model Comparison | Simple LR, Multiple LR, Decision Tree, Random Forest, KNN |
| Elbow Curve | RMSE vs k (1β20) to identify optimal k = 2 |
| Final Evaluation | MAE, MSE, RMSE, RΒ² on held-out test set |
- No missing values and no duplicate rows found in the dataset
- GDX_Close (Gold Miners ETF) has the strongest positive correlation with GLD (
+0.92) - SF_Price (Silver) is the second most correlated feature (
+0.87) - USDI_Price (US Dollar Index) shows the strongest inverse relationship (
-0.74) - USO_Close (Oil ETF) has the highest negative correlation among commodity features (
-0.19) - Outlier analysis performed via IQR method on skewed distributions
- Heatmap confirms multicollinearity between equity indices (SP_close, DJ_close)
Contributions, issues and feature requests are welcome!
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m "feat: add amazing feature" - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request π
Please follow Conventional Commits for commit messages.
Distributed under the MIT License. See LICENSE for more information.
Built with β€οΈ by Anubhab
If this project helped you, please consider giving it a β - it means a lot!