Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Price Predictor

A complete, end-to-end Machine Learning project built in Python to predict used car prices based on features like brand, age, kilometers driven, fuel type, transmission, and owner history.

This project follows a clean production-grade directory structure, separating data preprocessing, model training, evaluation, inference, and a web-based user interface using Streamlit.


Project Structure

car_price_predictor/
│
├── data/
│   └── car_dataset.csv       # Raw dataset
│
├── models/
│   ├── linear_regression.pkl # Saved Linear Regression model & preprocessor
│   ├── lasso.pkl             # Saved Lasso model & preprocessor
│   └── random_forest.pkl     # Saved Random Forest model & preprocessor
│
├── src/
│   ├── __init__.py           # Makes src a package
│   ├── preprocess.py         # Data loading, feature engineering, IQR outlier removal, OHE
│   ├── train.py              # Pipeline fitting, scaling, and model training
│   ├── evaluate.py           # Model testing, R2 score, and MAE comparison
│   └── predict.py            # Command-line interactive inference script
│
├── app.py                    # Interactive web application (Streamlit)
└── README.md                 # Project documentation

Features & Engineering

  • Feature Engineering: Extracts car brands from model names, computes vehicle age dynamically relative to the current year, and applies a log transformation (np.log) to the selling price to handle skewed distributions.

  • Data Leakage Prevention: Isolates outlier removal (using the Interquartile Range / IQR method) strictly to the training set (km_driven), and fits the StandardScaler exclusively on training data before transforming the test data.

  • Column Alignment: Utilizes dynamic reindexing during inference to ensure consistency between runtime inputs and trained one-hot encoded feature spaces.

Installation & Setup

  1. Clone the repository / Navigate to the root directory:
cd car_price_predictor
  1. Install the required dependencies: Ensure you have Python installed, then install the necessary packages:
pip install -r requirements.txt

How to Run the Project

  1. Train the Models To train the models (Linear Regression, Lasso, and Random Forest), serialize them, and save them into the models/ folder, run:
python -m src.train
  1. Evaluate Model Performance To compare all trained models against the test dataset using metrics like R-squared Score and Mean Absolute Error (MAE), run:
python -m src.evaluate
  1. Run Command-Line Predictions To make a quick prediction via the terminal using an interactive model selection prompt, run:
python -m src.predict
  1. Launch the Streamlit Web App To run the interactive web interface locally in your browser:
streamlit run app.py

About

An end-to-end machine learning web app that predicts used car prices using a complete data pipeline, multiple regression models, and an interactive Streamlit interface.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages