Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions car-price-prediction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# CarCast - Used Car Price Prediction

CarCast is an end-to-end data science + web application project that estimates the fair market price of used cars in India using machine learning.

This project starts from real listing data (sourced from CarDekho), goes through data understanding, cleaning, preprocessing, model training, feature engineering, model re-training, and finally serves predictions through a FastAPI backend with a React frontend.

## What this project does

- Predicts used car selling price from core vehicle attributes.
- Provides deal analysis by comparing predicted value vs asking price.
- Exposes a clean API for prediction and model metadata.
- Delivers a user-facing web app where anyone can enter car details and get an instant estimate.

## Data snapshot

- Source dataset: `cardekho_dataset.csv` (CarDekho listings)
- Total raw records: **15,411**
- Raw columns: **14**
- Cleaned dataset: **15,411 x 13**
- Feature-engineered dataset: **15,411 x 22**
- Train/Test split (enhanced processed): **12,328 / 3,083**

## ML journey in short

1. Collected and explored used-car listing data.
2. Cleaned and preprocessed data.
3. Trained multiple baseline regressors.
4. Performed feature engineering to better capture depreciation, usage intensity, and brand/engine interactions.
5. Repeated preprocessing and model selection on enhanced data.
6. Selected **XGBoost Regressor** as final model and saved the full prediction pipeline.

## Final selected model

**Model:** XGBoost Regressor
**R2:** 0.9459
**MAE:** 97,149.24
**RMSE:** 201,768.88

The final model performance report is available in [model_performance_enhanced.csv](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/reports/model_performance_enhanced.csv).

## Tech stack

- **Data Science:** Python, Pandas, NumPy, scikit-learn, XGBoost, Matplotlib, Seaborn, Jupyter
- **Backend/API:** FastAPI, Pydantic, Uvicorn, Joblib
- **Frontend:** React, TypeScript, TanStack Router, TanStack Query, Tailwind CSS

## Important project resources

- Data files: [backend/data/](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/data)
- Notebooks (full DS workflow): [backend/notebooks/](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/notebooks)
- Saved model pipelines: [backend/models/](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/models)
- Full DS write-up: [documentation.md](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/documentation.md)

## Scope note

This is a strong portfolio data science project focused on model development and practical deployment. It is not positioned as a production-grade automotive pricing platform.
32 changes: 32 additions & 0 deletions car-price-prediction/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Backend (FastAPI + ML Inference)

This backend serves the trained used-car price prediction pipeline and exposes APIs for prediction, deal analysis, health checks, and model metadata.

## Quick setup

```bash
cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
```

API docs:
- Swagger: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`

## Main endpoints

- `GET /health`
- `GET /brands`
- `GET /brands/{brand}/models`
- `GET /model-metrics`
- `GET /model-info`
- `POST /predict`
- `POST /predict-with-asking`

## Notes

- Final model artifact is loaded from [full_pipeline.pkl](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/models/full_pipeline.pkl).
- Data science notebooks and dataset files are in [backend/notebooks/](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/notebooks) and [backend/data/](D:/Car-price-prediction-project.worktrees/car-price-prediction-documentation/backend/data).
Empty file.
56 changes: 56 additions & 0 deletions car-price-prediction/backend/app/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
from pathlib import Path
from typing import List, Dict

# Base directory
BASE_DIR = Path(__file__).resolve().parent.parent

# Model paths
MODEL_PATH = BASE_DIR / "models" / "full_pipeline.pkl"

# Data paths
DATA_DIR = BASE_DIR / "app" / "data"
BRANDS_PATH = DATA_DIR / "brands.json"
BMODELS_PATH = DATA_DIR / "models.json"
FEATURE_IMPORTANCE_PATH = DATA_DIR / "feature_importance.json"

# Luxury brands list
LUXURY_BRANDS = [
'Mercedes-Benz', 'BMW', 'Audi', 'Land Rover',
'Jaguar', 'Porsche', 'Lexus', 'Volvo', 'Mini',
'Mercedes-AMG', 'Maserati', 'Bentley', 'Rolls-Royce',
'Ferrari', 'Lamborghini', 'Mclaren', 'Aston Martin'
]

# Engine category bins
ENGINE_BINS = [0, 1500, 2500, 3500, 6000]
ENGINE_LABELS = ['Small', 'Mid', 'Large', 'Luxury']

# API settings
API_TITLE = "CarCast - Used Car Price Prediction API"
API_VERSION = "2.0.0"
API_DESCRIPTION = """
## CarCast API

A comprehensive API for used car price prediction with advanced features.

### Features:
- **Car Price Prediction**: Predict fair market price
- **Deal Analysis**: Compare predicted vs asking price
- **Model Metrics**: View model performance
- **Feature Importance**: Understand what drives prices
- **Brand/Model Data**: Get available brands and models
- **Prediction History**: Track past predictions
"""

# Model performance metrics (from your training)
MODEL_METRICS = {
"model_name": "XGBoost Regressor",
"r2_score": 0.9459,
"mae": 97149.24,
"rmse": 201768.88,
"training_samples": 12328,
"test_samples": 3083,
"features_count": 295,
"description": "XGBoost model trained on 15,240 used car listings with 11 base features and 9 engineered features"
}
34 changes: 34 additions & 0 deletions car-price-prediction/backend/app/data/brands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
"Audi",
"BMW",
"Bentley",
"Datsun",
"Ferrari",
"Force",
"Ford",
"Honda",
"Hyundai",
"ISUZU",
"Isuzu",
"Jaguar",
"Jeep",
"Kia",
"Land Rover",
"Lexus",
"MG",
"Mahindra",
"Maruti",
"Maserati",
"Mercedes-AMG",
"Mercedes-Benz",
"Mini",
"Nissan",
"Porsche",
"Renault",
"Rolls-Royce",
"Skoda",
"Tata",
"Toyota",
"Volkswagen",
"Volvo"
]
Loading
Loading