-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (58 loc) · 2.46 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pandas as pd
import streamlit as st
import numpy as np
import pickle
import matplotlib.pyplot as plt
model = pickle.load(open('model.pkl','rb'))
loc_encod = pickle.load(open('loc_encod','rb'))
type_encod = pickle.load(open('type_encod','rb'))
def predict(area,loc,bed,sqft,balc):
#preprocessing sqrt variable
sqft1 = np.log(sqft)
#preprocessing type variable
for i in range(0,len(type_encod)):
if(bed==type_encod.index[i]):
bed = type_encod.Encoded_label[i]
#preprocessing location variable
for i in range(0,len(loc_encod)):
if(loc==loc_encod.index[i]):
loc = loc_encod.encod_location[i]
#preprocessing area variable
if(area == 'Built-up Area'):
area = 0
elif(area == 'Carpet Area'):
area = 1
elif(area == 'Plot Area'):
area = 2
elif(area == 'Super built-up Area'):
area = 3
#data=[[area,loc,bed,sqft,balc]]
m = {'area_type':[area], 'location':[loc], 'no_bedroom':[bed], 'total_sqft':[sqft1], 'balcony':[balc]}
data = pd.DataFrame(m)
pred = model.predict(data)
prediction = np.round(np.exp(pred),2)
#calculating price per sqft
per_sqft = np.round(prediction*100000/sqft,0)
return prediction, per_sqft
def main():
st.title('Prediction of House Price in Bengaluru')
b2, about = st.beta_columns([9,1])
if about.button('About'):
st.write('Created by SUMANTHA.NTS dated 25/01/2021')
area, loc, bed = st.beta_columns(3)
area = area.selectbox('Area Type',('Built-up Area','Carpet Area','Plot Area','Super built-up Area'))
loc = loc.text_input('Location Name')
bed = bed.selectbox('House Type',('1 RK','1 BHK','2 BHK','3 BHK','4 BHK','5 BHK',
'6 BHK','7 BHK','8 BHK','9 BHK','10 BHK','11 BHK'))
sqft = st.number_input('Enter sqft value',value=100.0)
balc = st.number_input('Number of Balcony',value=1)
predi,b1, lis = st.beta_columns([1,3.2,1])
if lis.button('Locations List'):
st.sidebar.header('Locations List')
st.sidebar.dataframe(loc_encod.index)
if predi.button('Predict'):
b3, predi,b4 = st.beta_columns([0.5,10,0.5])
prediction, per_sqft = predict(area,loc,bed,sqft,balc)
predi.subheader('Predicted House Price is {} Lakhs with {} INR / sqft'.format(prediction,per_sqft))
if __name__=='__main__':
main()