Danydarizzler/apartment-price-zurich
0
Model Iterations Documentation
Task: Apartment Price Prediction (Regression)
Summary of Iterative Process
New Feature
`area_per_room` = living area (m²) / number of rooms
- Represents the average room size of the apartment
- Not included in prior exercises (Week 1 and Week 2 used
areaandroomsseparately) - Motivation: a 3-room apartment with 90 m² (30 m²/room) is worth more than one with 60 m² (20 m²/room), even with the same room count
Preprocessing Steps
- Load CSV data (
original_apartment_data_analytics_hs24.csv) - Drop rows with missing values (
dropna()) - Remove duplicate rows (
drop_duplicates()) - Engineer new feature:
area_per_room = area / rooms - Apply
StandardScalerto all features (inside sklearn Pipeline) - Evaluate with 5-fold cross-validation (R² metric)
Models Used
Evaluation Method
- Metric: R² (coefficient of determination)
- Validation strategy: 5-fold cross-validation on the full dataset
- Higher R² = better fit (1.0 = perfect, 0.0 = predicts mean, <0 = worse than mean)
Final Selected Model
Gradient Boosting Regressor (Iteration 2)
Reason for selection:
- Highest CV R² across all models and iterations
- Handles non-linear relationships between features and price
- Lower overfitting compared to Random Forest thanks to shallow trees (max_depth=4) and slow learning rate (0.05)
- Benefits from the new
area_per_roomfeature
Final features used (8 total):
rooms– number of roomsarea– living area in m²pop– municipality populationpop_dens– population density (per km²)frg_pct– percentage of foreign residentsemp– number of employees in municipalitytax_income– average taxable income in municipalityarea_per_room– new feature: average room size (area / rooms)
Application
The trained model is served via a Gradio web interface (app.py). Users select the number of rooms, living area, and municipality — the app returns the predicted monthly rent in CHF.
