This project aims to accurately predict second-hand car prices using various regression algorithms. The complete end-to-end machine learning pipeline covers Exploratory Data Analysis (EDA), extensive feature preprocessing, feature scaling, model training across multiple linear and regularized regression techniques, and model evaluation.
- Problem Type: Supervised Learning — Regression
-
Target Variable: Used Car Price (
y) -
Best Performing Model: Polynomial Regression (3rd Degree) with an
$R^2$ Score of 0.98 (98%) -
Key Workflow Steps: Data Cleaning
$\rightarrow$ Feature Encoding$\rightarrow$ EDA & Visualization$\rightarrow$ Correlation Analysis$\rightarrow$ Train-Test Split$\rightarrow$ Feature Scaling$\rightarrow$ Model Benchmarking.
- Language: Python 3.14
- Data Manipulation:
pandas,numpy - Data Visualization:
matplotlib,seaborn - Machine Learning & Preprocessing:
scikit-learn - Environment: Jupyter Notebook / PyCharm
Before feeding the data into machine learning models, raw features were transformed through a rigorous preprocessing pipeline:
- Data Type Conversions: Corrected misclassified data types across columns.
- Date Parsing & Transformations: Derived actionable vehicle age/usage metrics from historical date columns.
- Categorical Encoding:
- Label Encoding: Applied to nominal binary/low-cardinality categorical variables.
- Ordinal Encoding: Applied to ordinal categorical attributes preserving intrinsic rankings.
- Distribution and outlier checks were performed across key numerical features (e.g., mileage, engine size, vehicle age).
- Categorical distributions against price were inspected to uncover market pricing trends.
- Feature-to-feature and feature-to-target linear relationships were examined using a Pearson correlation matrix.
- A Seaborn Heatmap was generated to detect potential multicollinearity and highlight features with strong predictive power toward the target price.
-
Feature Matrix & Target Vector: Separated into independent variables (
$X$ ) and dependent target variable ($y$ ). - Train-Test Split: Split into training and validation sets to ensure reliable model evaluation and prevent data leakage.
-
Feature Scaling: Applied
StandardScalerto standardize feature scales for optimal performance in regularized models.
Multiple linear regression variants and regularized algorithms were trained and benchmarked using standard evaluation metrics:
- Mean Squared Error (MSE)
- Mean Absolute Error (MAE)
- Coefficient of Determination (
$R^2$ Score)
| Algorithm | Model Configuration | Performance Summary |
|---|---|---|
| Linear Regression | Baseline Ordinary Least Squares | Baseline performance |
| Polynomial Regression | Degree 3 | Best Performance ( |
| Ridge Regression | L2 Regularization | Reduced variance over standard linear model |
| Lasso Regression | L1 Regularization | Effective feature selection |
| ElasticNet | Combined L1 + L2 | Balanced penalty structure |
| RidgeCV | Cross-validated L2 Alpha search | Optimized hyperparameter tuning |
| LassoCV | Cross-validated L1 Alpha search | Optimized hyperparameter tuning |
| ElasticNetCV | Cross-validated ElasticNet search | Optimized hyperparameter tuning |
Key Finding: Third-degree Polynomial Regression captured complex non-linear relationships between vehicle specifications (e.g., age vs. mileage vs. engine capacity interaction) and market price, outperforming standard linear and regularized baselines significantly.
.
├── data/
│ └── used_cars.csv # Raw dataset (if applicable)
├── notebooks/
│ └── Car_Price_Prediction.ipynb # Main notebook containing EDA, preprocessing & modeling
├── README.md # Project documentation
└── requirements.txt # Python dependencies