dubattim/zurich-apartment-price-predictor
0
Apartment Price Prediction - Model Iterations Documentation
Task: Apartment Rental Price Prediction (Regression)
Overview
This project predicts monthly rental prices for apartments in the Canton of Zurich using a Random Forest regressor. The model was developed iteratively over three iterations, progressively adding new features and tuning hyperparameters. The final model achieves an R² of 0.66 using 5-fold cross-validation.
Summary of Iterative Process
Preprocessing Steps
- Data loading: Loaded 804 apartment listings from enriched dataset (week 2), merged with BFS municipality demographic data
- Missing value handling: Dropped rows missing essential features (rooms, area, price, population stats, coordinates)
- Outlier removal: Removed apartments with price < 200 or > 15,000 CHF, area < 10 or > 500 m², rooms <= 0
- Feature engineering:
- distance_to_zurich (NEW): Haversine distance in km from apartment to Zurich main station (47.3769°N, 8.5417°E). Computed per listing, then averaged per municipality for the prediction app.
- area_per_room: Living area divided by number of rooms
- Target transformation (Iteration 3): Applied
log1pto the rental price for training; predictions are converted back withexpm1 - String cleaning: Converted
tax_incomefrom formatted strings (e.g., "108'788") to float
Features Used (9 total)
Feature Importances (Final Model)
The newly engineered distance_to_zurich is the second most important feature (28%), confirming that proximity to the city center is a strong predictor of rental prices.
Evaluation Method
- Metric: R² (coefficient of determination)
- Validation: 5-fold cross-validation on the full dataset
- All models evaluated with the same CV splits for fair comparison
Final Selected Model
- Model: Random Forest Regressor
- Hyperparameters: nestimators=500, maxdepth=20, minsamplessplit=5, minsamplesleaf=2, random_state=42
- Target transformation: log1p (predictions converted back with expm1)
- CV R²: 0.6613 (±0.0501)
- Reason for selection: Highest cross-validation R² across all iterations and models. The log transformation improved performance by 0.07 R² over the non-log version.
Application
The Gradio web app (app.py) accepts:
- Number of rooms
- Living area (m²)
- Town (dropdown of 100+ Zurich-area municipalities)
It looks up municipality data from the enriched BFS dataset, computes area_per_room, and returns the predicted monthly rent in CHF.
