A machine learning project to predict used car prices in Tunisia. Features data preprocessing, exploratory data analysis (EDA), and regression modeling using Scikit-Learn.
# Tayara Car Price Predictor
A production-quality Python project that **scrapes**, **cleans**, and **models** used-car listings from tayara.tn to predict car prices using machine learning.
> **Best model:** XGBoost · MAE 15 853 DT · R² 0.28
> R² improves significantly with more data — see Results for details.
---
## Table of Contents
- Project Structure
- Quickstart
- Installation
- Usage
- Data Pipeline
- Feature Engineering
- Models
- Results
- Configuration
---
## Project Structure
```
tayara_project/
├── scraper.py # Selenium + BeautifulSoup scraper
├── preprocessing.py # Data cleaning and feature engineering
├── modelling.py # Model training and evaluation
├── pipeline.py # CLI runner
├── data/
│ ├── tayara_cars_raw.csv # Raw scraped data
│ └── tayara_cars_clean.csv # Cleaned, feature-engineered data
├── plots/ # Residual distribution plots
├── requirements.txt
└── README.md
```
---
## Quickstart
```bash
# 1. venv setup
pip install -r requirements.txt
# 2. Run the full pipeline (scrape → clean → model)
python pipeline.py --scrape --clean --model --max-pages 50
# 3. Or skip scraping if you already have raw data
python pipeline.py --clean --model
# 4. Scrape more data for better model performance
python pipeline.py --scrape --clean --model --max-pages 150
```
---
## Installation
**Requirements:** Python ≥ 3.10. No browser or ChromeDriver needed — the scraper uses plain HTTP requests.
```bash
pip install -r requirements.txt
```
**`requirements.txt`**
```
pandas>=2.0
numpy>=1.25
requests>=2.31
beautifulsoup4>=4.12
scikit-learn>=1.3
xgboost>=2.0
matplotlib>=3.7
seaborn>=0.13
```
---
## Usage
### Scraper only
```python
from scraper import TayaraScraper
scraper = TayaraScraper(
output_path="data/raw.csv",
ad_delay=1.0,
page_delay=1.5,
max_retries=4,
)
scraper.run(max_pages=50)
```
> **Resume after crash:** if the scraper stops mid-run, simply re-run the same command. It auto-detects the `.chec …