Logo Lanfrica

Aymannel04/Morocco-housing-project

Domaine:

socioeconomic

Type de record:

project
Créateur:
Aym
HĂ´te:
# Morocco Housing Price Prediction 🏠 End-to-end ML project predicting apartment prices in Rabat, Morocco — from web scraping to deployment. **🔗 Live Demo:** (morocco-housing-project.str…) ## Overview This project covers the full data science pipeline: **Scraping (Selenium) → Cleaning (regex/Pandas) → Modeling (Random Forest) → Deployment (Streamlit).** Unlike most student projects that rely on curated Kaggle datasets, the data here was self-collected from Avito.ma — making this as much a data engineering project as a machine learning one. ## Problem Statement Real estate pricing in Morocco lacks transparent, data-driven benchmarks. This project builds a baseline price estimator for Rabat apartments using surface area and neighborhood as primary signals — designed to be expandable to other Moroccan cities (V2). ## Data Pipeline ### 1. Web Scraping (`src/scraper.py`) - **Tool:** Selenium with WebDriverManager - **Source:** avito.ma — apartment sales listings in Rabat - **Robustness:** Explicit waits (`WebDriverWait`), per-ad error handling, randomized delays (2–5s) to mimic human browsing - **Output:** Raw CSV with listing text, extracted price, and source URL ### 2. Data Cleaning (`src/cleaning.py`) - Regex-based extraction of price, surface area, and location from unstructured listing text - Filters applied: - Price ≥ 10,000 DH (removes rentals and noise) - Surface > 20 m² (removes obvious errors) - Drops rows with missing price or surface - Custom neighborhood parser with fallback logic for non-standard formats ### 3. Modeling (`src/model.py`) - **Algorithm:** Random Forest Regressor (`n_estimators=100`) - **Pipeline:** `ColumnTransformer` with `OneHotEncoder` for categorical features (`quartier`, `ville`), passthrough for numerical (`surface_final`) - **Evaluation:** Mean Absolute Error on a held-out 20% test set - **Artifact:** Serialized model (`models/price_predictor.pkl`) for the Streamlit app ## Dataset (V1) | Property | Value | …