Update src/streamlit_app.py
Browse files- src/streamlit_app.py +76 -33
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,83 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
"""
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"""
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|