RMHalak's picture
Update app.py
5fa9478 verified
raw
history blame
2.74 kB
import streamlit as st
import pandas as pd
import pickle
from utils import create_new_features, normalize
min_dict = {'bedrooms': 0,
'bathrooms': 0,
'sqft_living': 370,
'sqft_lot': 638,
'floors': 1,
'waterfront': 0,
'view': 0,
'condition': 1,
'sqft_above': 370,
'sqft_basement': 0,
'yr_built': 1900,
'yr_renovated': 0,
'house_age': 0,
'years_since_renovation': 0}
max_dict = {'bedrooms': 9,
'bathrooms': 8,
'sqft_living': 13540,
'sqft_lot': 1074218,
'floors': 3,
'waterfront': 1,
'view': 4,
'condition': 5,
'sqft_above': 9410,
'sqft_basement': 4820,
'yr_built': 2014,
'yr_renovated': 2014,
'house_age': 114,
'years_since_renovation': 2014}
columns = ['bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot', 'floors',
'waterfront', 'view', 'condition', 'sqft_above', 'sqft_basement',
'yr_built', 'yr_renovated', 'house_age', 'years_since_renovation',
'has_basement', 'city_Algona', 'city_Auburn', 'city_Beaux Arts Village',
'city_Bellevue', 'city_Black Diamond', 'city_Bothell', 'city_Burien',
'city_Carnation', 'city_Clyde Hill', 'city_Covington',
'city_Des Moines', 'city_Duvall', 'city_Enumclaw', 'city_Fall City',
'city_Federal Way', 'city_Inglewood-Finn Hill', 'city_Issaquah',
'city_Kenmore', 'city_Kent', 'city_Kirkland', 'city_Lake Forest Park',
'city_Maple Valley', 'city_Medina', 'city_Mercer Island', 'city_Milton',
'city_Newcastle', 'city_Normandy Park', 'city_North Bend',
'city_Pacific', 'city_Preston', 'city_Ravensdale', 'city_Redmond',
'city_Renton', 'city_Sammamish', 'city_SeaTac', 'city_Seattle',
'city_Shoreline', 'city_Skykomish', 'city_Snoqualmie',
'city_Snoqualmie Pass', 'city_Tukwila', 'city_Vashon',
'city_Woodinville', 'city_Yarrow Point']
with open('./trained_model.pkl', 'rb') as file:
model = pickle.load(file)
new_pred = st.text_area('Enter text')
if new_pred:
new_pred = {key:0 for key in columns}
new_pred['date'] = pd.to_datetime('2014-07-10') # do not change
new_pred['bedrooms'] = 5
new_pred['bathrooms'] = 3
new_pred['sqft_living'] = 10000
new_pred['sqft_lot'] = 1000
new_pred['floors'] = 2
new_pred['waterfront'] = 1
new_pred['view'] = 3
new_pred['condition'] = 5
new_pred['sqft_above'] = 500
new_pred['sqft_basement'] = 500
new_pred['yr_built'] = 2012
new_pred['yr_renovated'] = 2013
new_pred['city_Bellevue'] = 1
new_pred = pd.DataFrame([new_pred])
new_pred = create_new_features(new_pred)
for col in numerical_features:
new_pred[col] = normalize(new_pred, col, min_dict, max_dict)
predicted_price = model.predict(new_pred)
st.json(predicted_price[0][0])