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.
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.
- 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
- Python
- Scikit-learn
- Pandas
- NumPy
- FastAPI
- Uvicorn
- Pickle
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
The project follows the complete ML workflow:
- Data Collection
- Data Cleaning
- Feature Engineering
- Data Preprocessing
- Model Training
- Model Evaluation
- Model Serialization
- API Deployment
Example input:
{
"year": 2018,
"present_price": 7.5,
"kms_driven": 25000,
"fuel_type": "Petrol",
"seller_type": "Dealer",
"transmission": "Manual",
"owner": 0
}{
"predicted_price": 6.82
}Clone the repository
git clone https://github.com/Abhhiiissshhek/car_price_api.git
cd car_price_apiCreate a virtual environment
python -m venv .venvActivate it
.venv\Scripts\activatesource .venv/bin/activateInstall dependencies
pip install -r requirements.txtpython run_training.pyThis will:
- preprocess the dataset
- train the regression model
- save the trained pipeline
Start the FastAPI server
uvicorn app.main:app --reloadThe API will be available at
http://127.0.0.1:8000
FastAPI automatically generates API documentation.
Swagger UI
http://127.0.0.1:8000/docs
ReDoc
http://127.0.0.1:8000/redoc
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
}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
The project is designed for deployment on platforms such as:
- Render
- Railway
- Azure App Service
- AWS
- Docker
- 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
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
Abhishek Prajapati
- GitHub: https://github.com/Abhhiiissshhek
- LinkedIn: https://www.linkedin.com/in/abhishekprajapati-ml
If you found this project useful, consider giving it a ⭐ Star on GitHub. Contributions, feedback, and suggestions are always welcome.