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.
| 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.
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.
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
Train (optional, artifacts are committed):
pip install -r requirements.txt
python ml/train.pyAPI:
pip install -r backend/requirements.txt
cd backend && uvicorn app.main:app --reload
# docs at http://localhost:8000/docsWeb app:
cd docs && python -m http.server 8080 # http://localhost:8080Tests:
cd backend && pytest -qInteractive 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"}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.