Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,82 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
with open('./trained_model.pkl', 'rb') as file:
|
6 |
-
|
7 |
|
8 |
new_pred = st.text_area('Enter text')
|
9 |
|
10 |
if new_pred:
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import pickle
|
4 |
+
from utils import create_new_features, normalize
|
5 |
+
|
6 |
+
min_dict = {'bedrooms': 0,
|
7 |
+
'bathrooms': 0,
|
8 |
+
'sqft_living': 370,
|
9 |
+
'sqft_lot': 638,
|
10 |
+
'floors': 1,
|
11 |
+
'waterfront': 0,
|
12 |
+
'view': 0,
|
13 |
+
'condition': 1,
|
14 |
+
'sqft_above': 370,
|
15 |
+
'sqft_basement': 0,
|
16 |
+
'yr_built': 1900,
|
17 |
+
'yr_renovated': 0,
|
18 |
+
'house_age': 0,
|
19 |
+
'years_since_renovation': 0}
|
20 |
+
|
21 |
+
max_dict = {'bedrooms': 9,
|
22 |
+
'bathrooms': 8,
|
23 |
+
'sqft_living': 13540,
|
24 |
+
'sqft_lot': 1074218,
|
25 |
+
'floors': 3,
|
26 |
+
'waterfront': 1,
|
27 |
+
'view': 4,
|
28 |
+
'condition': 5,
|
29 |
+
'sqft_above': 9410,
|
30 |
+
'sqft_basement': 4820,
|
31 |
+
'yr_built': 2014,
|
32 |
+
'yr_renovated': 2014,
|
33 |
+
'house_age': 114,
|
34 |
+
'years_since_renovation': 2014}
|
35 |
+
|
36 |
+
columns = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors',
|
37 |
+
'waterfront', 'view', 'condition', 'sqft_above', 'sqft_basement',
|
38 |
+
'yr_built', 'yr_renovated', 'house_age', 'years_since_renovation',
|
39 |
+
'has_basement', 'city_Algona', 'city_Auburn', 'city_Beaux Arts Village',
|
40 |
+
'city_Bellevue', 'city_Black Diamond', 'city_Bothell', 'city_Burien',
|
41 |
+
'city_Carnation', 'city_Clyde Hill', 'city_Covington',
|
42 |
+
'city_Des Moines', 'city_Duvall', 'city_Enumclaw', 'city_Fall City',
|
43 |
+
'city_Federal Way', 'city_Inglewood-Finn Hill', 'city_Issaquah',
|
44 |
+
'city_Kenmore', 'city_Kent', 'city_Kirkland', 'city_Lake Forest Park',
|
45 |
+
'city_Maple Valley', 'city_Medina', 'city_Mercer Island', 'city_Milton',
|
46 |
+
'city_Newcastle', 'city_Normandy Park', 'city_North Bend',
|
47 |
+
'city_Pacific', 'city_Preston', 'city_Ravensdale', 'city_Redmond',
|
48 |
+
'city_Renton', 'city_Sammamish', 'city_SeaTac', 'city_Seattle',
|
49 |
+
'city_Shoreline', 'city_Skykomish', 'city_Snoqualmie',
|
50 |
+
'city_Snoqualmie Pass', 'city_Tukwila', 'city_Vashon',
|
51 |
+
'city_Woodinville', 'city_Yarrow Point']
|
52 |
|
53 |
with open('./trained_model.pkl', 'rb') as file:
|
54 |
+
model = pickle.load(file)
|
55 |
|
56 |
new_pred = st.text_area('Enter text')
|
57 |
|
58 |
if new_pred:
|
59 |
+
new_pred = {key:0 for key in X_train.columns}
|
60 |
+
new_pred['date'] = pd.to_datetime('2014-07-10') # do not change
|
61 |
+
|
62 |
+
new_pred['bedrooms'] = 5
|
63 |
+
new_pred['bathrooms'] = 3
|
64 |
+
new_pred['sqft_living'] = 10000
|
65 |
+
new_pred['sqft_lot'] = 1000
|
66 |
+
new_pred['floors'] = 2
|
67 |
+
new_pred['waterfront'] = 1
|
68 |
+
new_pred['view'] = 3
|
69 |
+
new_pred['condition'] = 5
|
70 |
+
new_pred['sqft_above'] = 500
|
71 |
+
new_pred['sqft_basement'] = 500
|
72 |
+
new_pred['yr_built'] = 2012
|
73 |
+
new_pred['yr_renovated'] = 2013
|
74 |
+
new_pred['city_Bellevue'] = 1
|
75 |
+
new_pred = pd.DataFrame([new_pred])
|
76 |
+
|
77 |
+
new_pred = create_new_features(new_pred)
|
78 |
+
for col in numerical_features:
|
79 |
+
new_pred[col] = normalize(new_pred, col, min_dict, max_dict)
|
80 |
+
|
81 |
+
predicted_price = model.predict(new_pred)
|
82 |
+
st.json(predicted_price[0][0])
|