CoolFace
Apppublic

Andrin111111/apartment-price-prediction

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

Apartment Price Prediction

Task: Apartment Price Prediction (Regression)


Project Description

ML app that predicts monthly apartment rental prices in Kanton Zürich, built with Streamlit and deployed on Hugging Face Spaces using a Random Forest Regressor.

Dataset

  • —Source: Apartment listings in Kanton Zürich
  • —2400 entries, 18 original features
  • —Target variable: monthly rent price (CHF)

Preprocessing Steps

Iteration 1 (Baseline):

  • —Cleaned town names (stripped whitespace)
  • —Removed duplicates and outliers (price < 200 or > 9000)
  • —Dropped text columns (address, description_raw)
  • —One-Hot Encoding for town (Top 20 + Other)
  • —Standard Scaling
  • —80/20 train-test split

Iteration 2 (Improved):

  • —Feature Engineering (4 new features)
  • —Log-transformation of target variable
  • —Removed highly correlated features (>0.9)
  • —Hyperparameter tuning

Summary of Iterative Process

IterationObjectiveKey ChangesModels UsedCV Mean R²CV Std DevChange in PerformanceFit Diagnosis
1Build baseline model- Basic cleaning<br>- Missing value imputation<br>- One-hot encoding<br>- Standard scaling<br>- 5-fold CVLinear Regression<br>Random Forest (n_estimators=100)0.78 (RF)<br>0.72 (LR)0.06Baseline☑ Overfitting ☐ Underfitting ☐ Good Fit
2Improve generalization- Feature engineering<br>- Removed correlated features<br>- Log transform target<br>- Hyperparameter tuning<br>- 5-fold CVRidge (alpha=1.0)<br>Tuned Random Forest (nestimators=300, maxdepth=15)0.86 (RF)<br>0.82 (Ridge)0.03+0.08 improvement☐ Overfitting ☐ Underfitting ☑ Good Fit

Notes

Metric: R², RMSE (5-Fold Cross-Validation)

Created Features:

  • —Distance to Center (Haversine distance to Zürich)
  • —Room Density (rooms / area)
  • —Area per Room (area / rooms)
  • —Pop Density Income Ratio (popdens / taxincome)

Final Selected Features:

  • —rooms
  • —area
  • —pop_dens
  • —frg_pct
  • —tax_income
  • —distancetocenter
  • —room_density
  • —areaperroom
  • —town (One-Hot Encoded, Top 20)

Reason for Selection: Chosen based on feature importance, correlation analysis, and cross-validation performance.


Final Model

  • —Tuned Random Forest Regressor
  • —nestimators=300, maxdepth=15
  • —CV R² = 0.86
  • —Selected because: Best cross-validation performance with low variance

App Usage

  1. 1.Select apartment parameters in the sidebar
  2. 2.Click Predict Rent Price
  3. 3.View the predicted monthly rent in CHF

Project Structure

  • —app.py – Streamlit web application
  • —train_model.ipynb – Training notebook with full iterative process
  • —final_model.joblib – Trained model
  • —scaler.joblib – Fitted StandardScaler
  • —feature_order.json – Feature order for prediction
  • —app_config.json – App configuration (towns, coordinates)
  • —requirements.txt – Python dependencies
  • —data/ – Training dataset