-
Notifications
You must be signed in to change notification settings - Fork 0
/
House_pred.py
152 lines (141 loc) · 6.97 KB
/
House_pred.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import streamlit as st
import pandas as pd
import pickle
# Load the LabelEncoders
with open('label_house_encoders.pkl', 'rb') as f:
label_encoders = pickle.load(f)
# Load the trained model
with open('gbr_house_model.pkl', 'rb') as f:
gb = pickle.load(f)
# Function to transform user input to match the model's input
def transform_input(user_input, label_encoders):
user_input_encoded = user_input.copy()
for col, encoder in label_encoders.items():
if col in user_input.columns:
user_input_encoded[col] = encoder.transform(user_input[[col]].values.ravel())
return user_input_encoded
# Function to predict house price
def predict_price(user_input):
user_input_transformed = transform_input(user_input, label_encoders)
prediction = gb.predict(user_input_transformed.values.reshape(1, -1))[0]
return prediction
# Streamlit app
st.write("""
<style>
body {
color: #333;
font-family: Arial, sans-serif;
}
.container {
max-width: 800px;
margin: auto;
padding: 20px;
}
h1 {
color: #0078FF;
text-align: center;
}
h2 {
color: #333;
}
.prediction {
background-color: #f4f4f4;
padding: 10px;
border-radius: 5px;
margin-top: 20px;
}
.sidebar .sidebar-content h2 {
color: white;
font-weight: bold;
}
</style>
<div class="container">
<h1>HOURICEP</h1>
<p>This app predicts the <strong>House Price</strong>!</p>
</div>
""", unsafe_allow_html=True)
st.sidebar.markdown(
'<h3 style="color:white;">Your House Price Prediction App</h3>',
unsafe_allow_html=True
)
# Sidebar for user input
st.sidebar.markdown(
"""
<style>
.sidebar .sidebar-content h2 {
color: white;
font-weight: bold;
}
</style>
""",
unsafe_allow_html=True
)
st.sidebar.markdown(
'<h3 style="color:white;">Specify Input Parameters</h3>',
unsafe_allow_html=True
)
def user_input_features():
POSTED_BY = st.sidebar.selectbox('POSTED_BY', ['Owner', 'Dealer', 'Builder'])
UNDER_CONSTRUCTION = st.sidebar.selectbox('UNDER_CONSTRUCTION', [0, 1])
RERA = st.sidebar.selectbox('RERA', [0, 1])
BHK_NO = st.sidebar.slider('BHK_NO.', 1, 20, 2)
BHK_OR_RK = st.sidebar.selectbox('BHK_OR_RK', ['BHK', 'RK'])
SQUARE_FT = st.sidebar.number_input('SQUARE_FT', min_value=254, max_value=545500, value=500)
READY_TO_MOVE = st.sidebar.selectbox('READY_TO_MOVE', [0, 1])
RESALE = st.sidebar.selectbox('RESALE', [0, 1])
LONGITUDE = st.sidebar.slider('LONGITUDE', -37.713008, 89.912884, 0.0)
LATITUDE = st.sidebar.slider('LATITUDE', -121.761248, 152.962676, 0.0)
CITY = st.sidebar.selectbox('CITY', ['Bangalore', 'Mysore', 'Ghaziabad', 'Kolkata', 'Kochi', 'Jaipur', 'Mohali', 'Chennai', 'Siliguri', 'Noida', 'Raigad', 'Bhubaneswar', 'Wardha', 'Pune', 'Mumbai', 'Nagpur', 'Deoghar', 'Bhiwadi', 'Faridabad', 'Lalitpur', 'Maharashtra', 'Vadodara', 'Visakhapatnam', 'Vapi', 'Mangalore', 'Aurangabad', 'Ottapalam', 'Vijayawada', 'Belgaum', 'Bhopal', 'Lucknow', 'Kanpur', 'Gandhinagar', 'Pondicherry', 'Agra', 'Ranchi', 'Gurgaon', 'Udupi', 'Indore', 'Jodhpur', 'Coimbatore', 'Valsad', 'Palghar', 'Surat', 'Varanasi', 'Guwahati', 'Amravati', 'Anand', 'Tirupati', 'Secunderabad', 'Raipur', 'Vizianagaram', 'Thrissur', 'Satna', 'Madurai', 'Chandigarh', 'Shimla', 'Gwalior', 'Rajkot', 'Sonipat', 'Allahabad', 'Berhampur', 'Roorkee', 'Dharuhera', 'Latur', 'Durgapur', 'Panchkula', 'Solapur', 'Durg', 'Goa', 'Jamshedpur', 'Hazaribagh', 'Jabalpur', 'Hosur', 'Morbi', 'Hubli', 'Karnal', 'Patna', 'Bilaspur', 'Ratnagiri', 'Meerut', 'Kotdwara', 'Jalandhar', 'Amritsar', 'Patiala', 'Ludhiana', 'Alwar', 'Kota', 'Panaji', 'Kolhapur', 'Ernakulam', 'Bhavnagar', 'Bharuch', 'Asansol', 'Jhansi', 'Margao', 'Anantapur', 'Eluru', 'Bhilai', 'Dehradun', 'Guntur', 'Jalgaon', 'Udaipur', 'Gurdaspur', 'Neemrana', 'Hassan', 'Sindhudurg', 'Hoshangabad', 'Kottayam', 'Dhanbad', 'Navsari', 'Bahadurgarh', 'Nellore', 'Dhule', 'Tirunelveli', 'Cuttack', 'Haridwar', 'Nainital', 'Jamnagar', 'Kanchipuram', 'Kadi', 'Karad', 'Jagdalpur', 'Panipat', 'Muzaffarpur', 'Salem', 'Jhunjhunu', 'Gandhidham', 'Junagadh', 'Moradabad', 'Ahmednagar', 'Jalna', 'Bhiwani', 'Palakkad', 'Kannur', 'Karjat', 'Akola', 'Jind', 'Gaya', 'Ambala', 'Ajmer', 'Hajipur', 'Dharwad', 'Pudukkottai', 'Kollam', 'Ooty', 'Bhandara', 'Barabanki', 'Rajpura', 'Palwal', 'Aligarh', 'Erode', 'Rudrapur', 'Tenali', 'Ongole', 'Nizamabad', 'Puri', 'Dalhousie', 'Siddipet', 'Solan', 'Darbhanga', 'Kadapa', 'Kakinada', 'Agartala', 'Warangal', 'Haldwani', 'Osmanabad', 'Bhagalpur', 'Bardhaman', 'Rishikesh', 'Chandrapur', 'Bokaro', 'Jharsuguda', 'Bhimavaram', 'Kurnool', 'Amroha', 'Hapur', 'Sabarkantha', 'Harda', 'Ujjain', 'Thoothukudi', 'Karaikudi', 'Mathura', 'Gadhinglaj', 'Rewari', 'Godhra', 'Kharagpur', 'Srikakulam', 'Srinagar', 'Midnapore', 'Rayagada', 'Banswara', 'Shirdi', 'Rohtak', 'Pali', 'Hathras', 'Yavatmal', 'Balasore', 'Chhindwara', 'Bareilly', 'Vidisha', 'Thanjavur', 'Kangra', 'Bikaner', 'Rewa', 'Porbandar', 'Nagaur', 'Nanded', 'Rourkela', 'Nadiad', 'Gulbarga', 'Palanpur', 'Bhadrak', 'Kurukshetra', 'Dibrugarh', 'Sagar', 'Machilipatnam', 'Pathanamthitta', 'Bankura', 'Jammu', 'Idukki', 'Korba', 'Raigarh', 'Silchar', 'Arrah', 'Nagaon', 'Karwar', 'Dahod', 'Nagapattinam', 'Sikar', 'Angul', 'Baddi', 'Darjeeling', 'Raisen', 'Hoshiarpur', 'Beed', 'Gadarwara', 'Jajpur', 'Haldia', 'Chittoor', 'Faizabad', 'Malappuram', 'Betul', 'Surendranagar', 'Phagwara', 'Visnagar', 'Rajnandgaon', 'Cuddalore', 'Raichur', 'Sambalpur', 'Gondia', 'Vellore', 'Bharatpur', 'Bhuj', 'Siwan', 'Washim'])
data = {
'POSTED_BY': POSTED_BY,
'UNDER_CONSTRUCTION': UNDER_CONSTRUCTION,
'RERA': RERA,
'BHK_NO.': BHK_NO,
'BHK_OR_RK': BHK_OR_RK,
'SQUARE_FT': SQUARE_FT,
'READY_TO_MOVE': READY_TO_MOVE,
'RESALE': RESALE,
'LONGITUDE': LONGITUDE,
'LATITUDE': LATITUDE,
'CITY': CITY
}
features = pd.DataFrame(data, index=[0])
return features
input_data = user_input_features()
# Display specified input parameters
st.markdown("""
<style>
.parameters {
border: 1px solid #ddd;
padding: 20px;
border-radius: 5px;
background-color: #f9f9f9;
}
.sidebar .sidebar-content h2 {
color: white;
font-weight: bold;
}
</style>
<div class="parameters">
<h2>Specified Input Parameters</h2>
</div>
""", unsafe_allow_html=True)
st.write(input_data)
st.write('---')
# Predict and display the house price
prediction = predict_price(input_data)
st.markdown(f"""
<style>
.prediction {{
background-color: #eaf4ff;
padding: 20px;
border-radius: 5px;
text-align: center;
}}
</style>
<div class="prediction">
<h2>Your house predicted price</h2>
</div>
""", unsafe_allow_html=True)
st.write(f"{prediction:.2f} Lakh")
st.write('---')