File size: 3,486 Bytes
5009990
72c563a
2b1d5a0
73d35a1
1ee8b1b
1fb410d
44ae606
5009990
38c9486
 
5009990
 
e1095b2
aad4cf3
 
e932906
 
63cd6ad
3afae0b
cbc82da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3afae0b
a0ed761
ed7fdc5
 
2b1d5a0
a0ed761
1ee8b1b
cbc82da
44ae606
c450eeb
28361c2
50acdcd
c450eeb
445eb64
 
5658180
445eb64
 
 
cbc82da
3afae0b
ba26d4e
 
5009990
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#import the necessary dependencies
import streamlit as st
import streamlit.components.v1 as cmpnts
import shap
import numpy as np
import pandas as pd
import predictor

st.set_option('deprecation.showPyplotGlobalUse', False)

#INTERFACE

#Creating an empty dataset to use in the model
data = pd.DataFrame(np.zeros((1,60)),columns=predictor.X_test.columns, index=[0])

st.title("*The Ames, Iowa Housing Price Predictor*")
st.header("Description:")
st.subheader("This is a showcase of the regression model, which has been trained using LightGBM and Optuna for hyperparameter tuning on the Ames, Iowa Housing Dataset. On the side are the top 20 features which this model deems the most relevant towards housing prices. Please try from a range of different inputs!")

OverallQual = st.sidebar.slider("Overall Quality", 1, 5)
with st.sidebar:
    data["OverallQual"] = OverallQual
    GrLivingArea = st.slider("Above ground Living Area (sqft):", 0, 5000)
    data["GrLivArea"] = GrLivingArea
    YearBuilt = st.number_input("Year Built: ", value=2000, min_value=1800, max_value=2023)
    data["YearBuilt"] = YearBuilt
    TotalBsmtSF = st.number_input("Total Basement Square Footage:", value=0, min_value=0)
    data["TotalBsmtSF"] = TotalBsmtSF
    BsmtFinSF1 = st.number_input("Square Footage of Type 1 Basement (same as total if one type):", value=0, min_value=0)
    data["BsmtFinSF1"] = BsmtFinSF1
    data["YearRemodAdd"] = st.number_input("Year of Remodeling/Additions (same as year built if no remodeling)", value = 2000, min_value= 1800,max_value=2023)
    data["LotArea"] = st.slider("Lot Area:", 0, 5000)
    data["OverallCond"] = st.slider("Overall Condition of the House (5 being the best):", 1, 5)
    data["1stFlrSF"] = st.number_input("First Floor Square Footage:", min_value=0,value=0)
    data["GarageCars"] = st.slider("Number of Cars the Garage Can Hold:", 0, 10)
    data["2ndFlrSF"] = st.number_input("Second Floor Square Footage:", value=0, min_value=0)
    data["Fireplaces"] = st.slider("Number of Fireplaces:", 0, 10)
    data["Neighborhood"] = st.slider("Neighborhood:", 0, 24)
    data["GarageArea"] = st.number_input("Garage Area (sqft):", value= 0, min_value=0)
    data["BsmtFullBath"] = st.slider("Number of Full Bathrooms in the Basement:", 0, 5)
    data["FullBath"] = st.slider("Number of Full Bathroooms Above Ground:", 0, 5)
    data["HalfBath"] = st.slider("Number of Half Bathrooms Above Ground (no shower):", 0, 5)
    data["KitchenQual"] = st.slider("Quality of the Kitchen", 1, 5)
    data["OpenPorchSF"] = st.number_input("Open Porch Square Footage:", value=0, min_value=0)
    data["MoSold"] = st.slider("Month Sold:", 1,12)

from streamlit import components
def st_shap(plot, height=None):
    shap_html = f"<head>{shap.getjs()}</head><body>{plot.html()}</body>"
    cmpnts.html(shap_html, height=height)
    
#The button
if st.button("Calculate Your House Price!"):
    results = predictor.make_a_prediction(data)
    opt_f = '{0:.2f}'.format(results[0][0])
    unopt_f = '{0:.2f}'.format(results[1][0])
    st.subheader('Optimized with optuna: $' + opt_f)
    st.write("Below are the SHAP graphs which can be used to explain the decisions made by the model using the features provided for the *optimized* results.")
    force_plot_1 = predictor.create_opt_shap_models(data)
    st_shap(force_plot_1)
    
    st.subheader('Unoptimized: $' + unopt_f)
    force_plot_2 = predictor.create_unopt_shap_models(data)
    st_shap(force_plot_2)