Based on these metrics, I selected k = 4 clusters as a reasonable trade-off.
Cluster interpretation
Visualized clusters using PCA (2D projection).
Computed per-cluster averages (e.g., price_usd, engine_capacity, car_age, odometer_value, mileage_per_year) to interpret each cluster (e.g., “new, expensive, low-mileage cars” vs “old, high-mileage, cheap cars”).
image
The resulting cluster ID and distance-to-centroid were then used as additional features in the supervised models.
5. Regression Models training & evaluation
After feature engineering and clustering, I trained three more advanced models:
Linear Regression (with all engineered features)
Ridge Regression (L2-regularized linear model)
Random Forest Regressor
Input features included both original and engineered features (categorical + numeric + cluster-based).
Evaluation metrics:
image
I also analyzed:
Linear / Ridge coefficients (top influential features)
Random Forest feature importances
image
image
Winning Regression Model
The Random Forest Regressor was selected as the winning regression model because:
It achieved the highest R² and lowest error (MAE/RMSE) on the test set.
It handles non-linear relationships and complex interactions between features.
It benefits from the rich set of engineered and cluster-based features without requiring strict assumptions about data distribution.
6. Regression → Classification
To turn the regression problem into a classification one, I:
Used pd.qcut on price_usd to create 3 balanced classes:
Class 0: low price (0-3000)
Class 1: medium price (3000-7000)
Class 2: high price (7000-19000)
Stored this new target as price_class.
6.1 Class Balance
Verified that the classes are approximately balanced using:
Value counts
image
7. Classification Models
Using price_class as the target, I trained three classification models:
Logistic Regression (multinomial)
Random Forest Classifier
Gradient Boosting Classifier
All models use the same preprocessing pipeline (numeric + categorical transformers) as in the regression stage.
7.1 Evaluation
For each model, I computed:
Classification report
Precision, Recall, F1-score, Support for each class
Confusion matrix (visualized as a heatmap)
image
image
image
7.2 Business Interpretation: Precision vs Recall
I treated the high price class (price_class = 2) as the positive class.
In this context, recall is more important than precision:
The implication of low recall is that the model may miss expensive cars and classify them as cheap, which would
result in financial losses for the person selling the car.
On the other hand, low precision means that some of the cars classified as expensive are actually cheap,
creating temporary overpricing — but that’s something that can be corrected later
Errors types
A False Positive (car predicted as high-price but actually medium/low) simply means the car might be listed
a bit too high — the seller can always lower the price later.
A False Negative (high-price car predicted as low/medium) means lost potential profit.
Therefore, False Negatives are more critical than False Positives in this scenario.
7.3 Winning Classification Model
Based on the classification reports and confusion matrices, I selected the random forest model that best balances overall performance and especially recall on the high-price class.