This project is a comprehensive full-stack application that predicts the market price of used cars. It features a modern web interface built with Next.js, a high-performance backend API powered by FastAPI, and a machine learning model trained with XGBoost.
Live Demo: https://your-frontend-url.vercel.app (<- Replace this with your Vercel URL!)

- Project Overview
- Tech Stack
- Features
- The Machine Learning Model
- Getting Started
- API Endpoints
- Future Improvements
The goal of this project was to build a complete, end-to-end system for predicting used car prices. A user can input various details about a car—such as make, model, year, and mileage—into a user-friendly form. The application then leverages a trained machine learning model to provide an estimated market value in real-time.
This project demonstrates skills across the entire development stack, from data science and model training to backend API development and modern frontend design. It also includes role-based access control for a user/admin dashboard.
This project is built with a modern, high-performance tech stack:
- Framework: Next.js (React)
- Styling: Tailwind CSS (or specify what you used, e.g., Material-UI, CSS Modules)
- Deployment: Vercel
- Framework: FastAPI (Python)
- Server: Uvicorn
- Data Validation: Pydantic
- Deployment: Render
- Core Libraries: Scikit-learn, Pandas, NumPy
- Algorithm: XGBoost (Extreme Gradient Boosting)
- Workflow: Jupyter Notebook for exploration, Python scripts for final training.
- Real-Time Price Prediction: Instantly get a price estimate by filling out a simple form.
- User and Admin Dashboards: Role-based views to manage data and view history.
- Responsive Design: A clean, mobile-first interface that works on any device.
- Interactive API Documentation: Automatically generated by FastAPI (available at the
/docsendpoint).
The heart of this application is the predictive model. The development followed a rigorous, iterative process.
The model was trained on a dataset of approximately 10,000 used car listings. Key features included:
marque,modele,annee,kilometragepuissance_fiscale,energie,boite
To prepare the data for the model, a robust scikit-learn pipeline was constructed to perform the following steps:
- Outlier Removal: Prices in the top and bottom 1% were removed to create a more stable model.
- Target Encoding: The high-cardinality
modelefeature was intelligently encoded by replacing each model with its average price from the training data, preventing the curse of dimensionality. - One-Hot Encoding: Low-cardinality categorical features (
marque,energie,boite) were converted into a numerical format. - Scaling: All numerical features were standardized using
StandardScaler.
Several regression algorithms were tested, with XGBoost providing the best performance. The model was further optimized using RandomizedSearchCV to find the best hyperparameters.
The final champion model achieved the following performance on the unseen test set:
- R-squared (R²): 0.76
- Root Mean Squared Error (RMSE): ~18,885
This indicates that the model can explain 76% of the variance in car prices, making it a strong and reliable predictor.
To run this project locally, you will need to set up both the backend and frontend separately.
- Python 3.8+
- Node.js and npm (or yarn)
- Git
- Clone the repository:
git clone https://github.com/your-username/your-backend-repo.git cd your-backend-repo - Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the training script (optional, as the model is pre-trained):
python train.py
- Start the API server:
The API will be available at
uvicorn main:app --reload
http://120.0.0.1:8000.
- Clone the repository:
git clone https://github.com/your-username/your-frontend-repo.git cd your-frontend-repo - Install dependencies:
npm install
- Set up environment variables:
Create a
.env.localfile in the root and add the backend API URL:NEXT_PUBLIC_API_URL=http://127.0.0.1:8000 - Start the development server:
The application will be available at
npm run dev
http://localhost:3000.
The primary API endpoint is:
POST /predict- Description: Takes a JSON object with car details and returns a predicted price.
- Request Body:
{ "marque": "Peugeot", "modele": "208", "puissance_fiscale": 5, "kilometrage": 50000, "annee": 2020, "energie": "Essence", "boite": "Manuelle" } - Success Response:
{ "predicted_price": 55432.89 }
- Hyperparameter Tuning: Implement a more exhaustive search (e.g., more iterations or
GridSearchCV) to potentially boost the model's R² score further. - Advanced Feature Engineering: Create interaction features (e.g.,
km_per_year) or use domain knowledge to tier car brands into categories like 'Luxury' or 'Economy'. - Data Enrichment: Integrate external data, such as a car's original MSRP, to provide more context to the model.
- User Authentication: Implement a full JWT-based authentication system for the dashboard features.