Predicting used car prices in Morocco using machine learning and a Streamlit dashboard
# Car Price Prediction
A data science project that predicts used car prices in Morocco. It includes data cleaning, exploratory data analysis (EDA), machine learning model training and comparison, and an interactive Streamlit dashboard.
## Project Overview
The goal is to predict the price of a used car from its features (such as year, mileage, fuel type, gearbox, and fiscal power). Ten regression models were trained and compared. A Streamlit web app lets users explore the data and make live price predictions.
## Results
Ten models were compared using R² (higher is better). The best model was **Random Forest**.
| Model | R² |
|---|---|
| Random Forest | 0.62 |
| Extra Trees | 0.61 |
| HistGradientBoosting | 0.56 |
| KNN Regression | 0.50 |
| Gradient Boosting | 0.47 |
| Ridge Regression | 0.42 |
| Linear Regression | 0.39 |
## Project Structure
```
car-price-prediction/
├── Project(Advanced_data_science).ipynb # Main notebook: cleaning, EDA, modelling
├── Advanced Data Science Report.pdf # Full written report
├── data/data.zip # Datasets (raw + cleaned), zipped
├── app/ # Streamlit dashboard
│ ├── app.py # Home page
│ └── pages/ # Overview, EDA, Model Comparison, Predict, Map
├── models/ # Saved model files
├── outputs/ # Charts and result files
├── requirements.txt # Python packages needed
└── README.md
```
## How to Run
1. Clone this repository:
```
git clone
github.com
cd car-price-prediction
```
2. Unzip the datasets:
```
unzip data/data.zip -d .
```
This gives you `cars_dataframe.csv` (raw) and `cars_cleaned.csv` (cleaned).
3. Install the required packages:
```
pip install -r requirements.txt
```
4. Run the Streamlit dashboard:
```
streamlit run app/app.py
```
## Notes
- The best …