Aghiless commited on
Commit
6f33c97
Β·
verified Β·
1 Parent(s): 35f7362

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +97 -83
src/streamlit_app.py CHANGED
@@ -1,83 +1,97 @@
1
- import streamlit as st
2
- import pickle
3
- import numpy as np
4
-
5
- # ---------------------------------------------------
6
- # Load the trained model
7
- # ---------------------------------------------------
8
-
9
- model = pickle.load(open("housing_model.pkl", "rb"))
10
-
11
- # ---------------------------------------------------
12
- # App title and description
13
- # ---------------------------------------------------
14
-
15
- st.title("🏠 House Price Estimator")
16
-
17
- st.write(
18
- """
19
- This app estimates the value of a property in Île-de-France
20
- based on a simple regression model trained on real estate data.
21
- """
22
- )
23
-
24
- # ---------------------------------------------------
25
- # Sidebar inputs
26
- # ---------------------------------------------------
27
-
28
- st.sidebar.header("Property information")
29
-
30
- surface = st.sidebar.number_input(
31
- "Surface (mΒ²)",
32
- min_value=10,
33
- max_value=400,
34
- value=70
35
- )
36
-
37
- rooms = st.sidebar.number_input(
38
- "Number of rooms",
39
- min_value=1,
40
- max_value=10,
41
- value=3
42
- )
43
-
44
- neighborhood_score = st.sidebar.slider(
45
- "Neighborhood score",
46
- min_value=1,
47
- max_value=10,
48
- value=5
49
- )
50
-
51
- # ---------------------------------------------------
52
- # Prediction
53
- # ---------------------------------------------------
54
-
55
- if st.sidebar.button("Estimate price"):
56
-
57
- features = np.array([[surface, rooms, neighborhood_score]])
58
-
59
- prediction = model.predict(features)
60
-
61
- estimated_price = int(prediction[0])
62
-
63
- st.subheader("Estimated property price")
64
-
65
- st.success(f"{estimated_price:,.0f} €")
66
-
67
- # ---------------------------------------------------
68
- # Extra explanation
69
- # ---------------------------------------------------
70
-
71
- st.write("---")
72
-
73
- st.write(
74
- """
75
- **Model inputs**
76
-
77
- - Surface of the property (mΒ²)
78
- - Number of rooms
79
- - Neighborhood attractiveness score
80
-
81
- The model predicts the approximate **market price** of the property.
82
- """
83
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Installing packages into β€˜/usr/local/lib/R/site-library’
2
+ (as β€˜lib’ is unspecified)
3
+
4
+ also installing the dependency β€˜vroom’
5
+
6
+
7
+ Warning message in install.packages(c("readr", "dplyr", "ggplot2", "corrplot")):
8
+ β€œinstallation of package β€˜ggplot2’ had non-zero exit status”
9
+
10
+ Attaching package: β€˜dplyr’
11
+
12
+
13
+ The following objects are masked from β€˜package:stats’:
14
+
15
+ filter, lag
16
+
17
+
18
+ The following objects are masked from β€˜package:base’:
19
+
20
+ intersect, setdiff, setequal, union
21
+
22
+
23
+ corrplot 0.95 loaded
24
+
25
+ Rows: 52820 Columns: 5
26
+ ── Column specification ────────────────────────────────────────────────────────
27
+ Delimiter: ","
28
+ dbl (5): price, surface, rooms, price_m2, neighborhood_score
29
+
30
+ β„Ή Use `spec()` to retrieve the full column specification for this data.
31
+ β„Ή Specify the column types or set `show_col_types = FALSE` to quiet this message.
32
+ [1] "Dataset loaded successfully"
33
+ A tibble: 6 Γ— 5
34
+ price surface rooms price_m2 neighborhood_score
35
+ <dbl> <dbl> <dbl> <dbl> <dbl>
36
+ 121000 69 2 1753.623 6.200
37
+ 246000 49 2 5020.408 5.015
38
+ 318050 115 6 2765.652 6.350
39
+ 163000 42 2 3880.952 6.350
40
+ 150000 93 5 1612.903 6.350
41
+ 153000 46 2 3326.087 5.935
42
+ spc_tbl_ [52,820 Γ— 5] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
43
+ $ price : num [1:52820] 121000 246000 318050 163000 150000 ...
44
+ $ surface : num [1:52820] 69 49 115 42 93 46 32 83 70 25 ...
45
+ $ rooms : num [1:52820] 2 2 6 2 5 2 2 4 3 1 ...
46
+ $ price_m2 : num [1:52820] 1754 5020 2766 3881 1613 ...
47
+ $ neighborhood_score: num [1:52820] 6.2 5.02 6.35 6.35 6.35 ...
48
+ - attr(*, "spec")=
49
+ .. cols(
50
+ .. price = col_double(),
51
+ .. surface = col_double(),
52
+ .. rooms = col_double(),
53
+ .. price_m2 = col_double(),
54
+ .. neighborhood_score = col_double()
55
+ .. )
56
+ - attr(*, "problems")=<externalptr>
57
+ price surface rooms price_m2
58
+ Min. : 1 Min. : 1.00 Min. : 0.000 Min. : 0
59
+ 1st Qu.: 185000 1st Qu.: 40.00 1st Qu.: 2.000 1st Qu.: 3193
60
+ Median : 290000 Median : 62.00 Median : 3.000 Median : 4800
61
+ Mean : 405173 Mean : 69.16 Mean : 3.116 Mean : 7332
62
+ 3rd Qu.: 464598 3rd Qu.: 88.00 3rd Qu.: 4.000 3rd Qu.: 8341
63
+ Max. :2990000 Max. :482.00 Max. :24.000 Max. :666667
64
+ neighborhood_score
65
+ Min. : 3.885
66
+ 1st Qu.: 6.727
67
+ Median : 7.780
68
+ Mean : 7.870
69
+ 3rd Qu.: 9.290
70
+ Max. :20.504
71
+
72
+
73
+
74
+
75
+
76
+ Call:
77
+ lm(formula = price ~ surface + rooms + neighborhood_score, data = train)
78
+
79
+ Residuals:
80
+ Min 1Q Median 3Q Max
81
+ -1815140 -145637 -68531 35243 2767231
82
+
83
+ Coefficients:
84
+ Estimate Std. Error t value Pr(>|t|)
85
+ (Intercept) -467418.10 10358.66 -45.12 <2e-16 ***
86
+ surface 4932.35 76.81 64.21 <2e-16 ***
87
+ rooms -29954.53 2059.06 -14.55 <2e-16 ***
88
+ neighborhood_score 79383.79 1120.02 70.88 <2e-16 ***
89
+ ---
90
+ Signif. codes: 0 β€˜***’ 0.001 β€˜**’ 0.01 β€˜*’ 0.05 β€˜.’ 0.1 β€˜ ’ 1
91
+
92
+ Residual standard error: 341000 on 42252 degrees of freedom
93
+ Multiple R-squared: 0.2284, Adjusted R-squared: 0.2283
94
+ F-statistic: 4169 on 3 and 42252 DF, p-value: < 2.2e-16
95
+ [1] "RMSE: 339999.604607665"
96
+
97
+ [1] "Model results saved successfully"