YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π Diamond Price Prediction & Valuation System
An end-to-end Machine Learning web application designed to predict diamond retail prices with high accuracy using a Random Forest Regressor trained on the classic 53,940+ diamonds dataset. The application features an interactive Streamlit user interface allowing users to adjust the 4 C's and diamond proportions in real time to receive immediate valuations and confidence estimates.
π Project Overview
Diamond pricing is traditionally complex and heavily dependent on specific qualitative and quantitative grading metrics known as the 4 C's (Carat, Cut, Color, and Clarity) alongside geometric table and depth proportions.
This project encompasses:
- Exploratory Data Analysis (EDA): Feature correlations, distribution analysis, and scatter plots comparing diamond dimensions against price.
- Machine Learning Pipeline: Data transformation using
ColumnTransformerwithOneHotEncoderand modeling withRandomForestRegressor. - Interactive Web App: A responsive, modern Streamlit UI with cached model deserialization (
@st.cache_resource) for instant predictions and zero lag.
π Key Features
- Real-Time Price Valuation: Instant price estimates calculated dynamically as you adjust sliders and inputs.
- The 4 C's Controls:
- Carat: Precise weight control from 0.20 to 5.00 carats.
- Cut Quality:
Fair,Good,Very Good,Premium,Ideal. - Color Grade: From
D(completely colorless) toJ(faint color). - Clarity Grade: From
I1(included) toIF(internally flawless).
- Proportions & Dimensional Measurements: Adjustable Total Depth %, Table %, Length ($x$), Width ($y$), and Depth ($z$) in millimeters.
- Valuation Presets: Quick one-click setups for popular diamond types:
- 1.00ct Engagement Ring (Ideal)
- 0.50ct Budget Diamond
- 2.00ct Luxury Solitaire
- Confidence Range: Displays an estimated 95% price range based on the model's Mean Absolute Error ($MAE \approx $270$).
π Model Architecture & Performance
The model was trained on the standard Seaborn Diamonds dataset (80/20 train/test split, random state 42).
| Metric | Score / Value |
|---|---|
| Algorithm | Random Forest Regressor (n_estimators=100) |
| $R^2$ Score | ~0.981 (98.1% of variance explained) |
| Mean Absolute Error (MAE) | ~$270 |
| Pre-processing | One-Hot Encoding (drop='first', handle_unknown='ignore') for categorical variables, passthrough for continuous numericals |
π Repository Structure
Diamond Price Prediction/
βββ app.py # Streamlit web application
βββ diamond_model.pkl # Pre-trained Random Forest Regressor model (compressed ~62 MB, GitHub-friendly)
βββ encoder.pkl # Pre-fitted ColumnTransformer preprocessor
βββ model.ipynb # Jupyter Notebook with EDA, training, and evaluation
βββ requirements.txt # Project dependencies
βββ README.md # Project documentation
π οΈ Installation & Setup
1. Clone or Open the Repository
cd "Diamond Price Prediction"
2. Set Up a Virtual Environment (Optional, Recommended)
# Windows
python -m venv venv
venv\Scripts\activate
# macOS / Linux
python3 -m venv venv
source venv/bin/activate
3. Install Dependencies
pip install -r requirements.txt
4. Run the Streamlit Application
streamlit run app.py
The app will open automatically in your browser at:
π http://localhost:8501
π How to Use the App
- Select a Preset or Custom Setup: Use the sidebar dropdown to choose between quick presets or customize all parameters yourself.
- Configure the 4 C's:
- Adjust the Carat Weight slider.
- Select the Cut, Color, and Clarity grades matching your diamond's certificate (e.g., GIA or IGI).
- Fine-tune Dimensions: Adjust Depth %, Table %, and physical measurements ($x$, $y$, $z$) in millimeters.
- View Valuation: The estimated retail market price and 95% confidence range will update instantly in the valuation card on the right.
π¦ Requirements
- Python 3.9+
streamlitscikit-learnpandasnumpyseabornmatplotlib
π License
This project is open-source and available under the MIT License. # Diamond-Price-Predator