Senasu commited on
Commit
aa8a219
·
verified ·
1 Parent(s): fe80323

Uploaded main files

Browse files
House_Rent_Dataset.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sklearn.pipeline import Pipeline
2
+ from sklearn.compose import ColumnTransformer
3
+ from sklearn.preprocessing import StandardScaler, OneHotEncoder
4
+ import streamlit as st
5
+ import pandas as pd
6
+ import joblib
7
+
8
+ # Load data and model
9
+ df = pd.read_csv('House_Rent_Dataset.csv')
10
+ df['Extracted Floor'] = df['Floor'].str.extract(r'^(\d{1,2}|[A-Za-z]+)', expand=False)
11
+
12
+ def map_floors(floor):
13
+ if floor.startswith('Ground'):
14
+ return 0
15
+ elif floor.startswith('Upper'):
16
+ return 0
17
+ elif floor.startswith('Lower'):
18
+ return -1
19
+ else:
20
+ return floor
21
+
22
+ df['Extracted Floor'] = df['Extracted Floor'].apply(map_floors)
23
+
24
+ # Load the trained model
25
+ model = joblib.load('best_regression_model.pkl')
26
+
27
+ # Define the preprocessor and pipeline
28
+ preprocessor = ColumnTransformer(
29
+ transformers=[
30
+ ("num", StandardScaler(), ["BHK", "Size", 'Bathroom', 'Extracted Floor']),
31
+ ("cat", OneHotEncoder(), ["Area Type", "Area Locality", "City", 'Furnishing Status', 'Tenant Preferred', 'Point of Contact'])
32
+ ]
33
+ )
34
+ pipeline = Pipeline(steps=[("preprocessor", preprocessor), ("regressor", model)])
35
+
36
+ # Fit the pipeline on the data (optional, if you want to refit with the data)
37
+ pipeline.fit(df[['BHK', 'Size', 'Area Type', 'Area Locality', 'City',
38
+ 'Furnishing Status', 'Tenant Preferred', 'Bathroom', 'Point of Contact', 'Extracted Floor']], df["Rent"])
39
+
40
+ # Function to predict the price
41
+ def price_prediction(bhk, size, area_type, area_locality, city, furnishing_status, tenant_preferred, bathroom, point_of_contact, floor):
42
+ input_data = pd.DataFrame({
43
+ "BHK": [bhk],
44
+ "Size": [size],
45
+ "Area Type": [area_type],
46
+ "Area Locality": [area_locality],
47
+ "City": [city],
48
+ "Furnishing Status": [furnishing_status],
49
+ "Tenant Preferred": [tenant_preferred],
50
+ "Bathroom": [bathroom],
51
+ "Point of Contact": [point_of_contact],
52
+ "Extracted Floor": [floor]
53
+ })
54
+ prediction = pipeline.predict(input_data)[0]
55
+ return prediction
56
+
57
+ # Main function to render the Streamlit app
58
+ def main():
59
+ st.set_page_config(page_title="House Rent Prediction in India", layout="wide")
60
+
61
+ # App title and description
62
+ st.title("🏠 House Rent Prediction in India")
63
+ st.markdown("""
64
+ **Enter the house features** below to predict the rent.
65
+ Adjust the inputs to see how different characteristics affect the rent.
66
+ """)
67
+
68
+ # Add custom CSS for styling
69
+ st.markdown("""
70
+ <style>
71
+ .stButton>button {
72
+ background-color: #28a745;
73
+ color: white;
74
+ font-size: 18px;
75
+ border-radius: 5px;
76
+ padding: 10px 20px;
77
+ margin-top: 20px;
78
+ }
79
+ .stButton>button:hover {
80
+ background-color: #218838;
81
+ }
82
+ .stText {
83
+ font-size: 16px;
84
+ color: #333;
85
+ }
86
+ .stTitle {
87
+ color: #007bff;
88
+ }
89
+ </style>
90
+ """, unsafe_allow_html=True)
91
+
92
+ # Side bar inputs (Better structure and user-friendly)
93
+ st.sidebar.header("Enter House Details")
94
+
95
+ city = st.sidebar.selectbox("City", df["City"].unique())
96
+ bhk = st.sidebar.number_input("Number of Bedrooms, Hall, Kitchen", int(df["BHK"].min()), int(df["BHK"].max()))
97
+ size = st.sidebar.number_input("Size of the House in Square Feet", min_value=float(df["Size"].min()), max_value=float(df["Size"].max()), step=10.0)
98
+ bathroom = st.sidebar.number_input("Bathroom Number", 0, step=1)
99
+ floor = st.sidebar.number_input("Extracted Floor", -1, step=1)
100
+
101
+ # Dynamic options based on city selection
102
+ area_type = st.sidebar.selectbox("Area Type", df[df['City'] == city]['Area Type'].unique())
103
+ area_locality = st.sidebar.selectbox("Area Locality", df[df['City'] == city]['Area Locality'].unique())
104
+ tenant_preferred = st.sidebar.selectbox("Tenant Preferred", df["Tenant Preferred"].unique())
105
+ furnishing_status = st.sidebar.selectbox("Furnishing Status", df["Furnishing Status"].unique())
106
+ point_of_contact = st.sidebar.selectbox("Point of Contact", df["Point of Contact"].unique())
107
+
108
+ # Prediction button
109
+ if st.sidebar.button("Predict Rent"):
110
+ price = price_prediction(bhk, size, area_type, area_locality, city, furnishing_status, tenant_preferred, bathroom, point_of_contact, floor)
111
+ price = float(price)
112
+
113
+ # Display the result with enhanced visualization
114
+ st.subheader("Predicted Rent: 💲 **${:,.2f}**".format(price))
115
+ st.markdown("""
116
+ This is the estimated price based on the characteristics you provided.
117
+ Please note that the actual market rent may vary.
118
+ """)
119
+
120
+ if __name__ == "__main__":
121
+ main()
best_regression_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd04a521b67d7be76cfdc9257d32c72e8a573e19cbf959418a7f03cf74f914ac
3
+ size 268997
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ scikit-learn
2
+ streamlit
3
+ joblib