Below is the updated Jupyter Notebook tailored for the Geely Auto Car Price Dataset for price prediction (regression task). I've made the necessary modifications based on your description:
Task Shift: The original notebook was for classification (e.g., predicting a binary target). I've changed it to regression, as "price detection" implies predicting a continuous value like car price.
Updated metrics: Now uses R2 score, Mean Squared Error (MSE), and Root Mean Squared Error (RMSE) instead of ROC-AUC, accuracy, etc.
Updated models: Switched to regression models like LinearRegression, RandomForestRegressor, etc.
Dataset Assumptions:
The dataset is likely the "Geely Auto Car Price Dataset" (e.g., from Kaggle or similar sources). It typically includes features like "Car_Name", "Year", "Selling_Price", "Kms_Driven", "Fuel_Type", etc.
I've set the default DATA_PATH to a common path for this dataset (e.g., "data/car_price_dataset.csv"). You need to update this to your actual file path.
I've set the TARGET_COL to "Selling_Price" based on common datasets. Adjust this if your column name differs (e.g., "Price").
EDA Adjustments: Enhanced to focus on regression-specific insights, like distributions of numeric features and correlations with the price target.
Other Changes: The rest of the pipeline (data loading, preprocessing, model comparison, tuning, evaluation, and interpretability) has been adapted for regression.
Copy the entire code below into a new Jupyter Notebook file (e.g., .ipynb) and run it cell by cell. Make sure you have the dataset file ready.
markdown
# 🔍📊 Geely Auto Car Price Prediction: EDA ➜ Pre-processing ➜ Model Selection
**Author:** _your name_ | **Last update:** `2024-MM-DD`
*Objective:*
1. Import the Geely Auto Car Price Dataset.
2. Perform cleaning & exploratory data analysis (EDA) tailored for regression.
3. Build several regression ML models, compare them with cross-validation, tune the best one, evaluate on a test set, and interpret the results for price prediction insights.
*Dataset Notes:*
- Source: Geely Auto Car Price Dataset (e.g., from Kaggle).
- Target: A continuous variable like "Selling_Price" (regression).
- Features: Typically include "Car_Name", "Year", "Kms_Driven", "Fuel_Type", etc.
---
```python
# ╔════════════════════════════════════════════════════════════════════╗
# ║ 0 | SETUP ║
# ╚════════════════════════════════════════════════════════════════════╝
!pip -q install pandas numpy matplotlib seaborn scikit-learn xgboost shap joblib -U
import warnings, os, json, joblib, math
warnings.filterwarnings("ignore")
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split, cross_val_score, GridSearchCV
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.metrics import (mean_squared_error, r2_score, mean_absolute_error)
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from xgboost import XGBRegressor
python
# ╔════════════════════════════════════════════════════════════════════╗
# ║ 1 | LOAD DATA ║
# ╚════════════════════════════════════════════════════════════════════╝
DATA_PATH = "data/car_price_dataset.csv" # 👈 CHANGE ME (e.g., to your Kaggle download path)
TARGET_COL = "Selling_Price" # 👈 CHANGE ME if your target column is different (e.g., "Price")
df = pd.read_csv(DATA_PATH)
print(f"Shape: {df.shape}")
df.head()
# ╔════════════════════════════════════════════════════════════════════╗
# ║ 9 | PERSIST MODEL ║
# ╚════════════════════════════════════════════════════════════════════╝
MODEL_PATH = "best_price_model.joblib"
joblib.dump(best_model, MODEL_PATH)
print(f"🎉 Saved best model to {MODEL_PATH}")
🎬 Wrap-up
We compared {len(models)} baseline regression algorithms; {best_name} with tuned hyper-parameters produced the highest cross-validated R2 score.
Key drivers of car prices (top features) were visualized, providing insights into factors like mileage, year, or fuel type.
The trained model was saved for downstream inference or deployment (e.g., predicting prices for new cars).
🚀 Next steps: Experiment with more feature engineering (e.g., extracting age from 'Year', handling outliers in 'Kms_Driven'), add polynomial features, or use AutoML for better regression performance. If you encounter issues with the dataset, double-check for missing values in the target column.
code
### Quick Tips for You:
- **Run the Notebook:** Start from the top and execute each cell sequentially. It should take 5-10 minutes depending on your machine.
- **Common Issues:**
- If the dataset has a different structure, you might need to add custom cleaning in section 2.
- Ensure your target column (`TARGET_COL`) is numeric; if not, convert it (e.g., remove currency symbols).
- If you get errors about missing libraries, restart the kernel after installing.
- **Enhancements:** For deeper insights, you could add time-based features (e.g., if 'Year' is present) or handle multicollinearity in EDA.
If you need further customizations (e.g., specific EDA plots or additional models), let me know! 🚀