Skip to content
Mustafa-elsherifPublic

About

Facet: diamond price intelligence with calibrated XGBoost valuation, SHAP explainability, a deal finder, and a browser-native dashboard.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

32 Commits

Folders and files

Repository files navigation

Facet

Facet

Diamond Price Intelligence

Estimate a fair price for any diamond, see why, and find the stones listed for less than they are worth. Built on a gradient-boosting model trained on 53,771 graded diamonds.

Live app → · Model notebook · API

Python FastAPI XGBoost Tests


What Facet does

Feature Description
Instant appraisal Set carat, cut, colour, clarity and proportions → a fair-value estimate with an honest 80% range, updated live.
Transparent reasoning Every estimate is decomposed into the attributes that moved the price, relative to a typical stone.
Deal finder Scores listed stones against their modelled worth and ranks them by value index (listed ÷ modelled).
Plain-English search "1 carat ideal cut under $6,000 best value" is parsed into filters and sorted by value.
Similar stones Nearest-neighbour discovery over the catalogue from any appraisal.
Assistant A grounded chat that answers questions on valuations, price drivers and deals using the live model and catalogue - interpreting short or casual input (even a bare budget like "6000") and offering quick-choice buttons so you're never stuck. It runs fully offline in the browser by default; when the API is deployed with a GEMINI_API_KEY server environment variable, it can also reply in the visitor's own language. No key is ever handled in the browser.

The web app runs the exact production model client-side. The trained XGBoost trees are exported to the browser, so the live demo needs no server and gives the same numbers as the API.


The model

A tuned XGBoost regressor on log(price), with cut/colour/clarity ordinal-encoded on the GIA quality scale. Benchmarked honestly against a standardized Ridge baseline and explained with SHAP.

Model R² MAE RMSE MAPE
Ridge (baseline) 0.9492 $460 $890 11.6%
XGBoost (shipped) 0.9832 $259 $512 6.2%

Training is offline and one-shot: ml/train.py serializes the model, metrics, SHAP importance and the browser bundle into backend/artifacts/ and docs/data/. The API and the web app only ever load artifacts, so nobody waits for training. The full CRISP-DM analysis lives in notebooks/diamonds_analysis.ipynb and matches the shipped model exactly.


Project structure

facet/
├── ml/train.py # one-shot training + artifact/browser export
├── backend/
│ ├── app/ # FastAPI service (model, schemas, routes)
│ ├── artifacts/ # serialized model, metrics, metadata, SHAP
│ ├── tests/ # pytest API suite
│ └── Dockerfile
├── docs/ # static editorial dashboard (served by GitHub Pages)
│ ├── index.html
│ ├── assets/ # styles.css, app.js, model.js (in-browser scorer)
│ └── data/ # model trees + scored sample (exported)
├── notebooks/ # CRISP-DM analysis (live-defense notebook)
└── data/diamonds.csv # dataset

Run it locally

Train (optional, artifacts are committed):

pip install -r requirements.txt
python ml/train.py

API:

pip install -r backend/requirements.txt
cd backend && uvicorn app.main:app --reload
# docs at http://localhost:8000/docs

Web app:

cd docs && python -m http.server 8080 # http://localhost:8080

Tests:

cd backend && pytest -q

REST API

Interactive docs at /docs. Core endpoints:

Method Path Purpose
POST /predict Fair value + 80% range for a diamond
POST /explain Prediction + per-feature SHAP contributions
GET /deals Under-priced stones, ranked by value index
POST /search Natural-language catalogue search
POST /similar Nearest stones to a given diamond
GET /meta · /health Model metadata/metrics · liveness
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" \
 -d '{"carat":1.0,"cut":"Ideal","color":"F","clarity":"VS1","depth":61.5,"table":57}'
# {"price":5091,"low":4541,"high":5707,"currency":"USD"}

Deployment

The web app is served by GitHub Pages from the docs/ folder on main. The API is containerized (backend/Dockerfile) and deploy-ready. See DEPLOYMENT.md for the one remaining host step.


Estimates are decision support, not a certified appraisal.

About

Facet: diamond price intelligence with calibrated XGBoost valuation, SHAP explainability, a deal finder, and a browser-native dashboard.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages