Andrin111111/apartment-price-prediction
0
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
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
- Select apartment parameters in the sidebar
- Click Predict Rent Price
- 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
