# Ghana Housing Price Prediction — End-to-End Pipeline
## ⚠️ Important note on data
No live, clean public dataset of Ghana housing prices was accessible in this environment.
To demonstrate the **full pipeline** (not just modeling), a realistic synthetic dataset (3,000 listings)
was generated using known Ghana real-estate patterns: Accra/Tema price premiums, gated-community
and pool premiums, distance-to-CBD depreciation, property age depreciation, etc.
**Before using this in production, `01_generate_data.py` must be replaced with a real data source**
(e.g. scraped/licensed data from meQasa, Jiji Ghana, or Ghana Statistical Service records).
The pipeline architecture (EDA → features → training → evaluation → deployment) stays identical either way.
## Pipeline stages
|File|Stage|What it does|
|-|-|-|
|`src/01_generate_data.py`|Data Collection|Builds `data/ghana_housing.csv` (3,000 rows, 14 columns)|
|`src/02_eda_and_preprocessing.py`|EDA + Feature Engineering|Checks nulls, price by city/type, correlations, one-hot encoding, engineered features|
|`src/03_train_models.py`|Modeling + Evaluation|Trains 4 models, compares MAE/RMSE/R²/MAPE, saves the best one|
|`src/04_app.py`|Deployment|Flask REST API (`/predict`, `/health`) serving live predictions|
## Results (on held-out 20% test set)
|Model|MAE (GHS)|RMSE (GHS)|R²|MAPE|
|-|-|-|-|-|
|**Gradient Boosting (chosen)**|139,624|194,359|**0.891**|12.8%|
|Ridge Regression|158,857|210,611|0.872|17.3%|
|Linear Regression|158,878|210,620|0.872|17.3%|
|Random Forest|159,886|219,165|0.862|15.7%|
**Gradient Boosting** was selected because it gave the best accuracy **(highest R²)** and the lowest prediction errors, making it the strongest model for housing price prediction.
## Top price drivers found by the model
- Plot size
- Floor size
- City (Tamale/Cape Coast/Kumasi vs. Accra)
- Distance to CBD
- Property age
- Property type
## Running it
```bash
pip install pandas numpy scikit-learn joblib flask
python3 src/01_genera …