allantacuelwvsu commited on
Commit
a9bdc1c
·
1 Parent(s): e5f155c

ubra app = 30 mins, git debug = 4 hours. good shi

Browse files
Files changed (5) hide show
  1. .gitignore +5 -0
  2. README.md +11 -0
  3. app.py +117 -0
  4. datasets/Delhi.csv +0 -0
  5. requirements.txt +7 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ ..//
2
+
3
+ venv/
4
+ .git
5
+ __pycache__/
README.md CHANGED
@@ -1,13 +1,24 @@
1
  ---
 
2
  title: Delhi Housing Price
3
  emoji: 🐨
4
  colorFrom: yellow
5
  colorTo: indigo
 
 
 
 
 
 
6
  sdk: streamlit
7
  sdk_version: 1.42.2
8
  app_file: app.py
9
  pinned: false
 
10
  short_description: this app uses logreg to predict housing prices in delhi
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ <<<<<<< HEAD
3
  title: Delhi Housing Price
4
  emoji: 🐨
5
  colorFrom: yellow
6
  colorTo: indigo
7
+ =======
8
+ title: 'Logistic Regression: Delhi Housing Price Prediction'
9
+ emoji: 🏠
10
+ colorFrom: green
11
+ colorTo: orange
12
+ >>>>>>> 9f2b567 (ubra app = 30 mins, git debug = 4 hours. good shi)
13
  sdk: streamlit
14
  sdk_version: 1.42.2
15
  app_file: app.py
16
  pinned: false
17
+ <<<<<<< HEAD
18
  short_description: this app uses logreg to predict housing prices in delhi
19
+ =======
20
+ short_description: this app runs logistic regression to predict pricing
21
+ >>>>>>> 9f2b567 (ubra app = 30 mins, git debug = 4 hours. good shi)
22
  ---
23
 
24
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ from sklearn.linear_model import LinearRegression
7
+ from sklearn.model_selection import train_test_split
8
+ from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
9
+
10
+ # Load
11
+ df = pd.read_csv("datasets/Delhi.csv")
12
+
13
+ # Preprocess
14
+ df = pd.get_dummies(df, columns=["Location"], drop_first=True) # One-hot encode locations
15
+ X = df.drop("Price", axis=1)
16
+ y = df["Price"]
17
+ median_price = y.median()
18
+
19
+ # Train
20
+ X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=1)
21
+ model = LinearRegression()
22
+ model.fit(X_train, y_train)
23
+ y_pred = model.predict(X_val)
24
+
25
+ # App
26
+ st.title("Delhi Housing Price Prediction")
27
+ tab1, tab2 = st.tabs(["Model Performance", "Price Predictor"])
28
+
29
+ with tab1:
30
+ # Model Assessment
31
+ st.header("Model Performance")
32
+
33
+ # Compute regression evaluation metrics
34
+ mae = mean_absolute_error(y_val, y_pred)
35
+ mse = mean_squared_error(y_val, y_pred)
36
+ r2 = r2_score(y_val, y_pred)
37
+
38
+ # Display regression metrics
39
+ st.write(f"**Mean Absolute Error (MAE):** {mae:,.2f}")
40
+ st.write(f"**Mean Squared Error (MSE):** {mse:,.2f}")
41
+ st.write(f"**R² Score:** {r2:.2f}")
42
+ st.divider()
43
+
44
+ with tab2:
45
+ # User Input
46
+ st.header("Price Prediction")
47
+ col1, col2 = st.columns(2)
48
+ with col1:
49
+ area = st.slider("Area (sq. ft)", 500, 5000, 1500)
50
+ bedrooms = st.slider("Number of Bedrooms", 1, 6, 3)
51
+ is_resale = st.radio("Resale or New?", ["Resale", "New"]) == "New"
52
+ location = st.selectbox("Location", df.columns[df.columns.str.startswith("Location_")].str.replace("Location_", ""))
53
+ with col2:
54
+ is_swimming_pool = st.checkbox("Has Swimming Pool")
55
+ is_car_parking = st.checkbox("Has Car Parking")
56
+ is_ac = st.checkbox("Has Air Conditioning")
57
+ is_wifi = st.checkbox("Has Wifi")
58
+ is_microwave = st.checkbox("Has Microwave")
59
+ is_tv = st.checkbox("Has TV")
60
+ is_dining_table = st.checkbox("Has Dining Table")
61
+ is_sofa = st.checkbox("Has Sofa")
62
+ is_wardrobe = st.checkbox("Has Wardrobe")
63
+ is_refrigerator = st.checkbox("Has Refrigerator")
64
+
65
+ # Process Input Data
66
+ input_data = np.zeros(len(X.columns)) # Create zero array matching feature length
67
+ input_data[0] = area
68
+ input_data[1] = bedrooms
69
+ input_data[2] = int(is_resale)
70
+ input_data[3] = int(is_swimming_pool)
71
+ input_data[4] = int(is_car_parking)
72
+ input_data[5] = int(is_ac)
73
+ input_data[6] = int(is_wifi)
74
+ input_data[7] = int(is_microwave)
75
+ input_data[8] = int(is_tv)
76
+ input_data[9] = int(is_dining_table)
77
+ input_data[10] = int(is_sofa)
78
+ input_data[11] = int(is_wardrobe)
79
+ input_data[12] = int(is_refrigerator)
80
+
81
+ # Set the correct location column to 1
82
+ loc_index = list(X.columns).index(f"Location_{location}")
83
+ input_data[loc_index] = 1
84
+
85
+ # Predict & Output
86
+ predicted_price = model.predict([input_data])[0]
87
+
88
+ # Set colors kag descs kay bigaon
89
+ price_diff = (predicted_price - median_price) / median_price
90
+ if price_diff < -0.2:
91
+ color = "#ff4d4d" # Below Median
92
+ category = "Below Median Price"
93
+ description = "This price is significantly lower than the median price in this area. The property may lack premium features and amenities or be in a less desirable location."
94
+ elif -0.2 <= price_diff < -0.05:
95
+ color = "#ff944d" # Slightly Below
96
+ category = "Slightly Below Median Price"
97
+ description = "This price is slightly below the median range, which could indicate a competitive offer for budget-conscious buyers."
98
+ elif -0.05 <= price_diff <= 0.05:
99
+ color = "#ffff4d" # In Median Range
100
+ category = "In Median Price Range"
101
+ description = "This price falls within the typical range for this area, making it a standard market price."
102
+ elif 0.05 < price_diff <= 0.2:
103
+ color = "#94ff4d" # Slightly Above
104
+ category = "Slightly Above Median Price"
105
+ description = "This price is slightly higher than the median, possibly due to added features such as better amenities or a prime location."
106
+ else:
107
+ color = "#4dff4d" # Above Median
108
+ category = "Above Median Price"
109
+ description = "This price is significantly above the median, suggesting a premium property with high-end features, amenities, and an excellent location."
110
+
111
+ # Result
112
+ st.subheader("Predicted House Price (INR)")
113
+ st.write(f"₹{predicted_price:,.2f}")
114
+ st.markdown(f'<h3 style="color:{color};">{category}</h3>', unsafe_allow_html=True)
115
+ st.write(description)
116
+ st.caption("Dataset is small so expect anomalous output (negative prices).")
117
+ st.divider()
datasets/Delhi.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ matplotlib==3.8.0
2
+ numpy==2.2.3
3
+ pandas==2.2.3
4
+ scikit_learn==1.2.2
5
+ seaborn==0.13.2
6
+ streamlit==1.30.0
7
+ streamlit==1.42.2