-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
56 lines (43 loc) · 2.13 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import pandas as pd
import xgboost
# Title
st.header("Paris Housing Price - Machine Learning App")
squareMeters = st.number_input("Enter house size (in square meters):")
made = st.number_input("Enter year made:")
numPrevOwners = st.number_input("Enter number of previous owners:")
numberOfRooms = st.number_input("Enter number of rooms:")
floors = st.number_input("Enter number of floors:")
basement = st.number_input("Enter basement size (in square meters):")
attic = st.number_input("Enter attic size (in square meters):")
garage = st.number_input("Enter garage size (in square meters):")
cityCode = st.number_input("Enter building city code: ")
cityPartRange = st.number_input("Enter city part range: ")
isNewBuilt = st.selectbox("Is this house newly built?", ("Yes", "No"))
hasYard = st.selectbox("Does this house has a yard?", ("Yes", "No"))
hasPool = st.selectbox("Does this house has a pool?", ("Yes", "No"))
hasStormProtector = st.selectbox("Does this house has a storm protector?", ("Yes", "No"))
hasStorageRoom = st.selectbox("Does this house has a storage room?", ("Yes", "No"))
hasGuestRoom = st.number_input("Enter number of guest rooms this house has:")
boolean_cols = ['hasYard', 'hasPool', 'isNewBuilt', 'hasStormProtector']
preds = ['squareMeters', 'numberOfRooms',
'floors', 'cityPartRange', 'numPrevOwners', 'made',
'basement', 'attic', 'garage', 'hasStorageRoom',
'hasGuestRoom', 'hasYard', 'hasPool', 'isNewBuilt', 'hasStormProtector', 'countFac']
# If button is pressed
if st.button("Submit"):
# Unpickle classifier
model = xgboost.XGBRegressor()
model.load_model("model.bin")
# Store inputs into dataframe
X = pd.DataFrame([[squareMeters, numberOfRooms,
floors, cityPartRange, numPrevOwners, made,
basement, attic, garage, hasStorageRoom,
hasGuestRoom, hasYard, hasPool, isNewBuilt, hasStormProtector]], columns=preds[:-1])
X = X.replace(["Yes", "No"], [1, 0])
X['countFac']=X[boolean_cols].sum(axis=1)
X.drop(boolean_cols, inplace=True, axis=1)
# Get prediction
prediction = model.predict(X)[0]
# Output prediction
st.text(f"The price of this house is {prediction}")