Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Car Price Prediction API

A production-style Machine Learning API that predicts the selling price of a used car based on its specifications. The project demonstrates an end-to-end machine learning workflow, including data preprocessing, model training, model serialization, and deployment using FastAPI.


📌 Overview

Estimating the market value of a used car is an important problem for buyers, sellers, and dealerships. This project uses a machine learning model trained on historical car data to predict the expected selling price from various vehicle attributes.

The project is designed following a modular architecture to separate data preprocessing, model training, prediction, and API services, making it easy to maintain and extend.


✨ Features

  • End-to-end Machine Learning pipeline
  • FastAPI REST API for predictions
  • Modular project structure
  • Trained model serialization using Pickle
  • Automatic API documentation with Swagger UI
  • Data preprocessing pipeline
  • Ready for cloud deployment

🛠 Tech Stack

  • Python
  • Scikit-learn
  • Pandas
  • NumPy
  • FastAPI
  • Uvicorn
  • Pickle

📂 Project Structure

car-price-api/
│
├── app/
│   ├── main.py                 # FastAPI application
│   ├── schemas.py              # Request/Response models
│   └── routes.py               # API routes
│
├── src/
│   ├── data_preprocessing.py
│   ├── train.py
│   ├── predict.py
│   └── evaluate.py
│
├── models/
│   └── car_price_pipeline.pkl
│
├── data/
│   ├── train.csv
│   └── test.csv
│
├── run_training.py
├── requirements.txt
├── Procfile
└── README.md

🧠 Machine Learning Pipeline

The project follows the complete ML workflow:

  1. Data Collection
  2. Data Cleaning
  3. Feature Engineering
  4. Data Preprocessing
  5. Model Training
  6. Model Evaluation
  7. Model Serialization
  8. API Deployment

📊 Input Features

Example input:

{
  "year": 2018,
  "present_price": 7.5,
  "kms_driven": 25000,
  "fuel_type": "Petrol",
  "seller_type": "Dealer",
  "transmission": "Manual",
  "owner": 0
}

📤 Example Prediction

{
  "predicted_price": 6.82
}

🚀 Installation

Clone the repository

git clone https://github.com/Abhhiiissshhek/car_price_api.git

cd car_price_api

Create a virtual environment

python -m venv .venv

Activate it

Windows

.venv\Scripts\activate

Linux/macOS

source .venv/bin/activate

Install dependencies

pip install -r requirements.txt

▶️ Train the Model

python run_training.py

This will:

  • preprocess the dataset
  • train the regression model
  • save the trained pipeline

🌐 Run the API

Start the FastAPI server

uvicorn app.main:app --reload

The API will be available at

http://127.0.0.1:8000

📚 Interactive API Documentation

FastAPI automatically generates API documentation.

Swagger UI

http://127.0.0.1:8000/docs

ReDoc

http://127.0.0.1:8000/redoc

🔌 API Endpoint

Predict Car Price

POST

/predict

Request

{
  "year": 2018,
  "present_price": 7.5,
  "kms_driven": 25000,
  "fuel_type": "Petrol",
  "seller_type": "Dealer",
  "transmission": "Manual",
  "owner": 0
}

Response

{
  "predicted_price": 6.82
}

📈 Model Evaluation

The model is evaluated using standard regression metrics such as:

  • Mean Absolute Error (MAE)
  • Mean Squared Error (MSE)
  • Root Mean Squared Error (RMSE)
  • R² Score

☁️ Deployment

The project is designed for deployment on platforms such as:

  • Render
  • Railway
  • Azure App Service
  • AWS
  • Docker

🔮 Future Improvements

  • Docker containerization
  • CI/CD with GitHub Actions
  • Model versioning
  • Authentication for API endpoints
  • Request logging and monitoring
  • Batch prediction endpoint
  • Cloud deployment
  • Interactive frontend using Streamlit

📚 What I Learned

This project helped me gain practical experience with:

  • Machine Learning pipelines
  • Feature engineering
  • Model serialization
  • REST API development using FastAPI
  • Production-ready project structure
  • Deploying ML models as web services

👨‍💻 Author

Abhishek Prajapati


⭐ Support

If you found this project useful, consider giving it a ⭐ Star on GitHub. Contributions, feedback, and suggestions are always welcome.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages