Aghiless commited on
Commit
904814d
·
verified ·
1 Parent(s): 5fa6d3e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -78
src/streamlit_app.py CHANGED
@@ -1,24 +1,17 @@
1
  import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
-
5
 
6
  # ---------------------------------------------------
7
- # PAGE CONFIG
8
  # ---------------------------------------------------
9
 
10
  st.set_page_config(
11
- page_title="Île-de-France Housing Price Estimator",
12
  page_icon="🏠",
13
- layout="wide"
14
  )
15
 
16
  # ---------------------------------------------------
17
- # LOAD DATA
18
- # ---------------------------------------------------
19
-
20
- # ---------------------------------------------------
21
- # MODEL COEFFICIENTS (from R)
22
  # ---------------------------------------------------
23
 
24
  INTERCEPT = -467418.10
@@ -40,43 +33,43 @@ def predict_price(surface, rooms, neighborhood_score):
40
 
41
 
42
  # ---------------------------------------------------
43
- # TITLE
44
  # ---------------------------------------------------
45
 
46
  st.title("🏠 Île-de-France Housing Price Estimator")
47
 
48
  st.write(
49
  """
50
- This dashboard estimates housing prices using a **linear regression model**
51
- trained on the **DVF real estate dataset**.
52
  """
53
  )
54
 
55
  # ---------------------------------------------------
56
- # SIDEBAR INPUTS
57
  # ---------------------------------------------------
58
 
59
- st.sidebar.header("Property characteristics")
60
 
61
  surface = st.sidebar.slider(
62
  "Surface (m²)",
63
- 20,
64
- 300,
65
- 70
66
  )
67
 
68
  rooms = st.sidebar.slider(
69
  "Number of rooms",
70
- 1,
71
- 10,
72
- 3
73
  )
74
 
75
  neighborhood_score = st.sidebar.slider(
76
  "Neighborhood score",
77
- 3.0,
78
- 10.0,
79
- 7.0
80
  )
81
 
82
  # ---------------------------------------------------
@@ -93,68 +86,26 @@ if st.sidebar.button("Estimate price"):
93
 
94
 
95
  # ---------------------------------------------------
96
- # DATASET OVERVIEW
97
- # ---------------------------------------------------
98
-
99
- st.write("---")
100
- st.header("Dataset Overview")
101
-
102
- col1, col2, col3 = st.columns(3)
103
-
104
- col1.metric("Number of properties", len(df))
105
- col2.metric("Average price", f"{int(df['price'].mean()):,} €")
106
- col3.metric("Average price per m²", f"{int(df['price_m2'].mean()):,} €")
107
-
108
-
109
- # ---------------------------------------------------
110
- # PRICE DISTRIBUTION
111
- # ---------------------------------------------------
112
-
113
- st.write("---")
114
- st.header("Price Distribution")
115
-
116
- fig, ax = plt.subplots()
117
-
118
- ax.hist(df["price"], bins=50)
119
-
120
- ax.set_xlabel("Price (€)")
121
- ax.set_ylabel("Number of properties")
122
-
123
- st.pyplot(fig)
124
-
125
-
126
- # ---------------------------------------------------
127
- # PRICE VS SURFACE
128
  # ---------------------------------------------------
129
 
130
  st.write("---")
131
- st.header("Price vs Surface")
132
-
133
- fig2, ax2 = plt.subplots()
134
-
135
- ax2.scatter(df["surface"], df["price"], alpha=0.3)
136
 
137
- ax2.set_xlabel("Surface (m²)")
138
- ax2.set_ylabel("Price (€)")
139
-
140
- st.pyplot(fig2)
141
-
142
-
143
- # ---------------------------------------------------
144
- # MODEL EXPLANATION
145
- # ---------------------------------------------------
146
-
147
- st.write("---")
148
- st.header("Model")
149
-
150
- st.write("The prediction is based on the following linear regression model:")
151
 
152
  st.latex(
153
- r'''
154
  Price =
155
  -467418
156
  + 4932 \times Surface
157
  - 29954 \times Rooms
158
  + 79383 \times NeighborhoodScore
159
- '''
 
 
 
 
 
 
 
160
  )
 
1
  import streamlit as st
 
 
 
2
 
3
  # ---------------------------------------------------
4
+ # PAGE SETTINGS
5
  # ---------------------------------------------------
6
 
7
  st.set_page_config(
8
+ page_title="Housing Price Estimator",
9
  page_icon="🏠",
10
+ layout="centered"
11
  )
12
 
13
  # ---------------------------------------------------
14
+ # MODEL COEFFICIENTS (from R regression)
 
 
 
 
15
  # ---------------------------------------------------
16
 
17
  INTERCEPT = -467418.10
 
33
 
34
 
35
  # ---------------------------------------------------
36
+ # APP TITLE
37
  # ---------------------------------------------------
38
 
39
  st.title("🏠 Île-de-France Housing Price Estimator")
40
 
41
  st.write(
42
  """
43
+ Estimate the value of a property using a **linear regression model**
44
+ trained on real estate data from the DVF dataset.
45
  """
46
  )
47
 
48
  # ---------------------------------------------------
49
+ # USER INPUTS
50
  # ---------------------------------------------------
51
 
52
+ st.sidebar.header("Property Information")
53
 
54
  surface = st.sidebar.slider(
55
  "Surface (m²)",
56
+ min_value=20,
57
+ max_value=300,
58
+ value=70
59
  )
60
 
61
  rooms = st.sidebar.slider(
62
  "Number of rooms",
63
+ min_value=1,
64
+ max_value=10,
65
+ value=3
66
  )
67
 
68
  neighborhood_score = st.sidebar.slider(
69
  "Neighborhood score",
70
+ min_value=3.0,
71
+ max_value=10.0,
72
+ value=7.0
73
  )
74
 
75
  # ---------------------------------------------------
 
86
 
87
 
88
  # ---------------------------------------------------
89
+ # MODEL FORMULA
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # ---------------------------------------------------
91
 
92
  st.write("---")
 
 
 
 
 
93
 
94
+ st.write("### Model Formula")
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  st.latex(
97
+ r"""
98
  Price =
99
  -467418
100
  + 4932 \times Surface
101
  - 29954 \times Rooms
102
  + 79383 \times NeighborhoodScore
103
+ """
104
+ )
105
+
106
+ st.write(
107
+ """
108
+ The prediction is based on a **linear regression model** trained on
109
+ housing transactions in Île-de-France.
110
+ """
111
  )