CoolFace
Apppublic

Danydarizzler/apartment-price-zurich

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

Model Iterations Documentation

Task: Apartment Price Prediction (Regression)


Summary of Iterative Process

IterationObjectiveKey ChangesModels UsedCV Mean R²CV Std DevChange in PerformanceFit Diagnosis
1Build baseline model- Drop missing values<br>- Remove duplicates<br>- StandardScaler<br>- 5-fold CVLinear Regression<br>Random Forest (n=100)0.4739 (LR)<br>0.4648 (RF)0.0980 (LR)<br>0.1275 (RF)Baseline☐ Overfitting ☑ Underfitting ☐ Good Fit
2Improve with new feature & better models- All steps from Iter 1<br>- New feature: area_per_room<br>- 5-fold CVRidge (alpha=10)<br>Gradient Boosting (n=200, depth=4, lr=0.05)0.4786 (Ridge)<br>0.4977 (GB)0.1099 (Ridge)<br>0.1005 (GB)+0.0329 improvement☐ Overfitting ☐ Underfitting ☑ Good Fit

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 area and rooms separately)
  • —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

  1. 1.Load CSV data (original_apartment_data_analytics_hs24.csv)
  2. 2.Drop rows with missing values (dropna())
  3. 3.Remove duplicate rows (drop_duplicates())
  4. 4.Engineer new feature: area_per_room = area / rooms
  5. 5.Apply StandardScaler to all features (inside sklearn Pipeline)
  6. 6.Evaluate with 5-fold cross-validation (R² metric)

Models Used

ModelIterationHyperparametersNotes
Linear Regression1defaultBaseline, prone to underfitting
Random Forest1nestimators=100, randomstate=42Overfits without tuning
Ridge Regression2alpha=10.0L2 regularization reduces overfitting
Gradient Boosting2nestimators=200, maxdepth=4, learningrate=0.05, randomstate=42Best overall performer

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_room feature

Final features used (8 total):

  • —rooms – number of rooms
  • —area – living area in m²
  • —pop – municipality population
  • —pop_dens – population density (per km²)
  • —frg_pct – percentage of foreign residents
  • —emp – number of employees in municipality
  • —tax_income – average taxable income in municipality
  • —area_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.