Downloads · 30 days
0
RON2105/car-price-random-forest-ron-ben-zur
car-price-random-forest-ron-ben-zur is a machine learning model from RON2105. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
🚗 Car Price Prediction — Regression & Classification Models
Downloads · 30 days
0
Access
Public
Updated Dec 9, 2025
Repo size
44.8 MB
Likes
0
Public
Click a slice to open those files.
.pkl43.1 MB · 96%
From the Hugging Face model README
🚗 Car Price Prediction — Regression & Classification Models
Author: Ron Ben Zur
Intro to Data Science — Reichman University
📘 Google Colab Notebook:(https://colab.research.google.com/drive/1yfgzzOajlGRRlG_DkPs-r5txlwfvXTWm#scrollTo=ckPiOLWke74N)
🎥 Presentation Video
a recorded presentation summarizing the project, models, and results is available here: https://youtu.be/iYmsTmMMzJg ⸻
This project predicts car prices using two machine learning approaches:
✔️ Regression Task
Predicting the exact numerical price. Winning Model: Random Forest Regressor (fast configuration)
✔️ Classification Task
Predicting whether a car is cheap, mid-range, or expensive. Winning Model: Gradient Boosting Classifier
Both models are fully deployed as sklearn Pipelines with preprocessing.
⸻
The dataset contains ~19,237 vehicles with numeric + categorical features.
🔧 Engineered features include: • car_age • log_mileage • price_per_liter • engine_power_index • One-hot encoding • Standard scaling
⸻
📊 Price Distribution After Cleaning
The cleaned dataset shows a right-skewed price distribution, where most cars fall within lower to mid price ranges. The long tail on the right represents a small number of expensive vehicles. This confirms that car prices are not normally distributed and vary significantly across models and brands.
3. Exploratory Visualizations
🔍 Price vs Mileage
Higher mileage is generally associated with lower car prices. Most cars cluster at low mileage with a wide range of prices, while extremely high-mileage cars show consistently reduced pricing. The pattern reinforces the strong negative correlation between mileage and market value.⸻
🔍 Price vs Production Year
Newer cars tend to have significantly higher prices. Cars produced after 2010 show a dense cluster of high-value points, while older cars (before 2000) appear consistently cheaper. This highlights production year as one of the strongest predictors of price.
⸻
🔍 Price by Top Manufacturers (Boxplot)
Premium brands like Lexus, BMW, and Mercedes-Benz show consistently higher price ranges with wider variability. Manufacturers like Honda, Nissan, and Chevrolet display lower and more compact price distributions. This reflects clear brand-based segmentation in the car market.
⸻
The Random Forest model showed strong performance capturing non-linear relations.
📈 Regression Performance • MAE: ~9600 • RMSE: ~13400 • R²: ~0.12
🔥 Feature Importance (Regression)
Tree-based models (Random Forest and Gradient Boosting) achieve far higher R² scores compared to Linear Regression, confirming that non-linear models better capture the complex structure of car pricing. Linear Regression struggles due to the dataset’s non-linear relationships and diverse categorical features.⸻
Car prices were converted into 3 balanced classes using quantile binning: • 0 — Cheap • 1 — Mid-range • 2 — Expensive
⸻
Confusion Matrix – Gradient Boosting
The confusion matrix shows strong performance across all three classes, with most predictions falling on the diagonal. Misclassifications occur primarily between neighboring classes (e.g., Mid-range ↔ Expensive), which is expected due to overlapping price ranges.⸻
Model Comparison (Accuracy & F1 Score)
Gradient Boosting clearly outperforms Logistic Regression and Random Forest. It achieves the highest accuracy and best class balance, making it the strongest model for predicting whether a car is cheap, mid-range, or expensive.⸻
🏆 Winning Classification Model
✔ Gradient Boosting Classifier achieved the highest: • Accuracy: 0.887 • Weighted F1: 0.875
⸻
with open("winning_model.pkl", "rb") as f: model = pickle.load(f)
prediction = model.predict(df) print("Prediction:", prediction) Pipelines automatically preprocess input features. 7. Repository Contents File Description winning_model.pkl Regression pipeline winning_classification_model.pkl Classification pipeline README.md Project documentation /images/ Graphs used in this README 8. Author
Ron Ben Zur Intro to Data Science — Assignment #2 Reichman University ✔ Final Notes
This repository demonstrates a complete ML workflow including: • EDA • Data cleaning • Feature engineering • Regression modeling • Classification modeling • Model comparison • Confusion matrices • Deployment-ready pipelines on HuggingFace