Spaces:
Build error
Build error
#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) | |