Upload 6 files
Browse files- .gitattributes +1 -0
- V1_Ex.ipynb +0 -0
- apartments_data_enriched_with_new_features.csv +0 -0
- app.py +106 -0
- distance.png +3 -0
- raoul_aufgabe_mit_distance_to_hb.pkl +3 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
distance.png filter=lfs diff=lfs merge=lfs -text
|
V1_Ex.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
apartments_data_enriched_with_new_features.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %%
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
with open("raoul_aufgabe_mit_distance_to_hb.pkl", "rb") as f:
|
| 8 |
+
model = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
features = ['rooms', 'area', 'pop', 'pop_dens', 'frg_pct', 'emp', 'tax_income', 'room_per_m2', 'luxurious', 'temporary', 'furnished', 'area_cat_ecoded',
|
| 12 |
+
'(LUXURIÖS)', '(POOL)', '(SEESICHT)',
|
| 13 |
+
'(EXKLUSIV)', '(ATTIKA)', '(LOFT)', 'Kreis 6', 'Kreis 11', 'Kreis 12', 'Kreis 10',
|
| 14 |
+
'Kreis 4', 'Kreis 1', 'Kreis 9', 'Kreis 5', 'Kreis 7', 'Kreis 3',
|
| 15 |
+
'Kreis 2', 'Kreis 8', 'distance_to_hb']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from math import radians, sin, cos, sqrt, atan2
|
| 19 |
+
|
| 20 |
+
def haversine_distance(lat, lon, center_lat=47.3769, center_lon=8.5417):
|
| 21 |
+
R = 6371
|
| 22 |
+
dlat = radians(lat - center_lat)
|
| 23 |
+
dlon = radians(lon - center_lon)
|
| 24 |
+
a = sin(dlat / 2) ** 2 + cos(radians(lat)) * cos(radians(center_lat)) * sin(dlon / 2) ** 2
|
| 25 |
+
c = 2 * atan2(sqrt(a), sqrt(1 - a))
|
| 26 |
+
return R * c
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def predict_price(rooms, area, pop, pop_dens, frg_pct, emp, tax_income, room_per_m2,
|
| 30 |
+
luxurious, temporary, furnished, area_cat_ecoded, lux, pool, seesicht,
|
| 31 |
+
exklusiv, attika, loft, k6, k11, k12, k10, k4, k1, k9, k5, k7, k3, k2, k8,
|
| 32 |
+
lat, lon):
|
| 33 |
+
distance = haversine_distance(lat, lon)
|
| 34 |
+
input_data = pd.DataFrame([[rooms, area, pop, pop_dens, frg_pct, emp, tax_income, room_per_m2,
|
| 35 |
+
luxurious, temporary, furnished, area_cat_ecoded, lux, pool,
|
| 36 |
+
seesicht, exklusiv, attika, loft, k6, k11, k12, k10, k4, k1,
|
| 37 |
+
k9, k5, k7, k3, k2, k8, distance]],
|
| 38 |
+
columns=features)
|
| 39 |
+
pred = model.predict(input_data)[0]
|
| 40 |
+
return f"Estimated Rent Price: CHF {pred:.2f}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
inputs = [
|
| 44 |
+
gr.Number(label="Rooms"),
|
| 45 |
+
gr.Number(label="Area (m²)"),
|
| 46 |
+
gr.Number(label="Population"),
|
| 47 |
+
gr.Number(label="Population Density"),
|
| 48 |
+
gr.Number(label="Foreigners (%)"),
|
| 49 |
+
gr.Number(label="Employment"),
|
| 50 |
+
gr.Number(label="Taxable Income"),
|
| 51 |
+
gr.Number(label="Room per m²"),
|
| 52 |
+
gr.Checkbox(label="Luxurious"),
|
| 53 |
+
gr.Checkbox(label="Temporary"),
|
| 54 |
+
gr.Checkbox(label="Furnished"),
|
| 55 |
+
gr.Number(label="Area Category Encoded"),
|
| 56 |
+
gr.Checkbox(label="(LUXURIÖS)"),
|
| 57 |
+
gr.Checkbox(label="(POOL)"),
|
| 58 |
+
gr.Checkbox(label="(SEESICHT)"),
|
| 59 |
+
gr.Checkbox(label="(EXKLUSIV)"),
|
| 60 |
+
gr.Checkbox(label="(ATTIKA)"),
|
| 61 |
+
gr.Checkbox(label="(LOFT)"),
|
| 62 |
+
gr.Checkbox(label="Kreis 6"),
|
| 63 |
+
gr.Checkbox(label="Kreis 11"),
|
| 64 |
+
gr.Checkbox(label="Kreis 12"),
|
| 65 |
+
gr.Checkbox(label="Kreis 10"),
|
| 66 |
+
gr.Checkbox(label="Kreis 4"),
|
| 67 |
+
gr.Checkbox(label="Kreis 1"),
|
| 68 |
+
gr.Checkbox(label="Kreis 9"),
|
| 69 |
+
gr.Checkbox(label="Kreis 5"),
|
| 70 |
+
gr.Checkbox(label="Kreis 7"),
|
| 71 |
+
gr.Checkbox(label="Kreis 3"),
|
| 72 |
+
gr.Checkbox(label="Kreis 2"),
|
| 73 |
+
gr.Checkbox(label="Kreis 8"),
|
| 74 |
+
gr.Number(label="Latitude"),
|
| 75 |
+
gr.Number(label="Longitude")
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
examples = [
|
| 79 |
+
[3, 75, 100000, 1200, 30, 150000, 25000, 1.2, True, False, True, 1, True, False, True, False, True, False,
|
| 80 |
+
True, False, False, False, False, False, False, False, False, False, False, False,
|
| 81 |
+
47.3830, 8.5470],
|
| 82 |
+
|
| 83 |
+
[2, 55, 90000, 1500, 40, 140000, 22000, 1.3, False, True, True, 2, False, True, False, True, True, False,
|
| 84 |
+
False, False, False, False, True, False, False, False, False, False, False, False,
|
| 85 |
+
47.3750, 8.5275],
|
| 86 |
+
|
| 87 |
+
[4, 100, 130000, 1900, 28, 160000, 27000, 1.5, True, False, False, 3, True, True, True, False, False, True,
|
| 88 |
+
False, False, False, False, False, True, False, False, False, False, False, False,
|
| 89 |
+
47.3660, 8.5445],
|
| 90 |
+
|
| 91 |
+
[2, 60, 85000, 1100, 35, 135000, 21000, 1.1, False, False, True, 0, False, False, False, False, False, False,
|
| 92 |
+
False, False, False, False, False, False, False, False, False, False, False, False,
|
| 93 |
+
47.4100, 8.4900]
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
demo = gr.Interface(
|
| 97 |
+
fn=predict_price,
|
| 98 |
+
inputs=inputs,
|
| 99 |
+
outputs="text",
|
| 100 |
+
examples=examples,
|
| 101 |
+
title="Zürich Apartment Rent Estimator",
|
| 102 |
+
description="Predicts the estimated monthly rent (CHF) for an apartment in Zürich based on various features."
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
demo.launch()
|
| 106 |
+
# %%
|
distance.png
ADDED
|
Git LFS Details
|
raoul_aufgabe_mit_distance_to_hb.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:216710efc7a54e89c75f6c9ab0acf194a60c5148ac760b36becf2b83813fd039
|
| 3 |
+
size 6713529
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
scikit-learn
|