itsJasminZWIN commited on
Commit
8a0ace0
·
verified ·
1 Parent(s): f135845

Upload 4 files

Browse files
apartments_data_enriched_with_new_features (1).csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ import gradio as gr
3
+ import pandas as pd
4
+ import pickle
5
+
6
+ # Load model from file
7
+ model_filename = "random_forest_model.pkl"
8
+ with open(model_filename, mode="rb") as f:
9
+ random_forest_model = pickle.load(f)
10
+ #import dataset
11
+ df = pd.read_csv('apartments_data_enriched_with_new_features.csv')
12
+
13
+ locations = {
14
+ "Zürich": 261,
15
+ "Kloten": 62,
16
+ "Uster": 198,
17
+ "Illnau-Effretikon": 296,
18
+ "Feuerthalen": 27,
19
+ "Pfäffikon": 177,
20
+ "Ottenbach": 11,
21
+ "Dübendorf": 191,
22
+ "Richterswil": 138,
23
+ "Maur": 195,
24
+ "Embrach": 56,
25
+ "Bülach": 53,
26
+ "Winterthur": 230,
27
+ "Oetwil am See": 157,
28
+ "Russikon": 178,
29
+ "Obfelden": 10,
30
+ "Wald (ZH)": 120,
31
+ "Niederweningen": 91,
32
+ "Dällikon": 84,
33
+ "Buchs (ZH)": 83,
34
+ "Rüti (ZH)": 118,
35
+ "Hittnau": 173,
36
+ "Bassersdorf": 52,
37
+ "Glattfelden": 58,
38
+ "Opfikon": 66,
39
+ "Hinwil": 117,
40
+ "Regensberg": 95,
41
+ "Langnau am Albis": 136,
42
+ "Dietikon": 243,
43
+ "Erlenbach (ZH)": 151,
44
+ "Kappel am Albis": 6,
45
+ "Stäfa": 158,
46
+ "Zell (ZH)": 231,
47
+ "Turbenthal": 228,
48
+ "Oberglatt": 92,
49
+ "Winkel": 72,
50
+ "Volketswil": 199,
51
+ "Kilchberg (ZH)": 135,
52
+ "Wetzikon (ZH)": 121,
53
+ "Zumikon": 160,
54
+ "Weisslingen": 180,
55
+ "Elsau": 219,
56
+ "Hettlingen": 221,
57
+ "Rüschlikon": 139,
58
+ "Stallikon": 13,
59
+ "Dielsdorf": 86,
60
+ "Wallisellen": 69,
61
+ "Dietlikon": 54,
62
+ "Meilen": 156,
63
+ "Wangen-Brüttisellen": 200,
64
+ "Flaach": 28,
65
+ "Regensdorf": 96,
66
+ "Niederhasli": 90,
67
+ "Bauma": 297,
68
+ "Aesch (ZH)": 241,
69
+ "Schlieren": 247,
70
+ "Dürnten": 113,
71
+ "Unterengstringen": 249,
72
+ "Gossau (ZH)": 115,
73
+ "Oberengstringen": 245,
74
+ "Schleinikon": 98,
75
+ "Aeugst am Albis": 1,
76
+ "Rheinau": 38,
77
+ "Höri": 60,
78
+ "Rickenbach (ZH)": 225,
79
+ "Rafz": 67,
80
+ "Adliswil": 131,
81
+ "Zollikon": 161,
82
+ "Urdorf": 250,
83
+ "Hombrechtikon": 153,
84
+ "Birmensdorf (ZH)": 242,
85
+ "Fehraltorf": 172,
86
+ "Weiach": 102,
87
+ "Männedorf": 155,
88
+ "Küsnacht (ZH)": 154,
89
+ "Hausen am Albis": 4,
90
+ "Hochfelden": 59,
91
+ "Fällanden": 193,
92
+ "Greifensee": 194,
93
+ "Mönchaltorf": 196,
94
+ "Dägerlen": 214,
95
+ "Thalheim an der Thur": 39,
96
+ "Uetikon am See": 159,
97
+ "Seuzach": 227,
98
+ "Uitikon": 248,
99
+ "Affoltern am Albis": 2,
100
+ "Geroldswil": 244,
101
+ "Niederglatt": 89,
102
+ "Thalwil": 141,
103
+ "Rorbas": 68,
104
+ "Pfungen": 224,
105
+ "Weiningen (ZH)": 251,
106
+ "Bubikon": 112,
107
+ "Neftenbach": 223,
108
+ "Mettmenstetten": 9,
109
+ "Otelfingen": 94,
110
+ "Flurlingen": 29,
111
+ "Stadel": 100,
112
+ "Grüningen": 116,
113
+ "Henggart": 31,
114
+ "Dachsen": 25,
115
+ "Bonstetten": 3,
116
+ "Bachenbülach": 51,
117
+ "Horgen": 295
118
+ }
119
+
120
+ # Define the core prediction function
121
+ def predict_apartment(rooms, area, town, tax_income, luxurious, temporary, furnished, room_per_m2, zurich_city):
122
+ bfs_number = locations[town]
123
+ df1 = df[df['bfs_number']==bfs_number].copy()
124
+ df1.reset_index(inplace=True)
125
+ df1.loc[0, 'rooms'] = rooms
126
+ df1.loc[0, 'area'] = area
127
+ df1.loc[0, 'tax_income'] = tax_income
128
+ df1.loc[0, 'luxurious'] = luxurious
129
+ df1.loc[0, 'temporary'] = temporary
130
+ df1.loc[0, 'furnished'] = furnished
131
+ df1.loc[0, 'room_per_m2'] = room_per_m2
132
+ df1.loc[0, 'zurich_city'] = zurich_city
133
+
134
+ if len(df1) > 1: # if there are more than one record with the same bfs_number, calculate the mean price
135
+ df1[0, 'price'] = df1['price'].mean()
136
+
137
+ prediction = random_forest_model.predict(df1[['rooms', 'area', 'pop', 'pop_dens', 'frg_pct', 'emp', 'tax_income', 'room_per_m2', 'luxurious', 'temporary', 'furnished', 'area_cat_ecoded', 'zurich_city']])
138
+ return np.round(prediction[0], 0)
139
+
140
+ # Create the Gradio interface
141
+ iface = gr.Interface(
142
+ fn=predict_apartment,
143
+ inputs=[
144
+ gr.Number(label="Rooms"),
145
+ gr.Number(label="Area"),
146
+ gr.Dropdown(choices=list(locations.keys()), label="Town"),
147
+ gr.Number(label="Tax Income"),
148
+ gr.Checkbox(label="Luxurious"),
149
+ gr.Checkbox(label="Temporary"),
150
+ gr.Checkbox(label="Furnished")
151
+ ],
152
+ outputs=gr.Number(),
153
+ examples=[
154
+ [4.5, 120, "Dietlikon", 90000, 2000, True, False, True],
155
+ [3.5, 60, "Winterthur", 85000, 1500, False, True, False],
156
+ [2.5, 40, "Zürich", 110000, 5000, True, True, True],
157
+ ]
158
+ )
159
+
160
+ iface.launch()
random_forest_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d863df2d1203ffa5af8797ef4c62d7a5a505959710479727c1e1c8d97e24c32
3
+ size 3518996
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ scikit-learn