Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from sklearn.model_selection import train_test_split
|
|
6 |
import lightgbm as lgb
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
|
|
9 |
|
10 |
|
11 |
@st.experimental_memo
|
@@ -63,32 +64,34 @@ def buil_UI(X):
|
|
63 |
|
64 |
input_val = buil_UI(X)
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
-
# MSSubClass = st.sidebar.slider("What is the building class?", min_value = 20, max_value=190)
|
69 |
-
# OverallQual = st.sidebar.slider("What is the Overall material and finish quality?", min_value = 1, max_value=10)
|
70 |
-
# YearBuilt = st.sidebar.slider("In which year was the Original construction date?", min_value = 1872 , max_value=2010)
|
71 |
-
# YearRemodAdd = st.sidebar.slider("In which year was it remodelled?", min_value = 1950, max_value=2010)
|
72 |
-
# BsmtUnfSF = st.sidebar.slider("What is the Unfinished square feet of basement area?", min_value = 0, max_value=2336)
|
73 |
-
# TotalBsmtSF = st.sidebar.slider("What is the Total square feet of basement area?", min_value = 0, max_value=6110)
|
74 |
-
# FirstFlrSF = st.sidebar.slider("What is the First Floor square feet?", min_value = 334, max_value=4692)
|
75 |
-
# SecondFlrSF = st.sidebar.slider("What is the Second floor square feet?", min_value = 0, max_value=2065)
|
76 |
-
# GrLivArea = st.sidebar.slider("What is the Above grade (ground) living area square feet?", min_value = 334, max_value=5642)
|
77 |
-
# FullBath = st.sidebar.slider("What is the number of full bathrooms?", min_value = 0, max_value=3)
|
78 |
-
# HalfBath = st.sidebar.slider("What is the number of Half baths?", min_value = 0, max_value=2)
|
79 |
-
# TotRmsAbvGrd = st.sidebar.slider("What is the number of Total rooms above grade (does not include bathrooms)?", min_value = 0, max_value=14)
|
80 |
-
# Fireplaces = st.sidebar.slider("What is the number of fireplaces?", min_value = 0, max_value=3)
|
81 |
-
# GarageCars = st.sidebar.slider("What is the garage capacity in car sizes?", min_value = 0, max_value=4)
|
82 |
-
# GarageArea = st.sidebar.slider("What is the size of garage in square feet?", min_value = 0, max_value=1418)
|
83 |
-
# MoSold = st.sidebar.slider("In which month was it sold?", min_value = 1, max_value=12)
|
84 |
-
# YrSold = st.sidebar.slider("In which year was it sold?", min_value = 2006, max_value=2010)
|
85 |
-
|
86 |
-
# compute SHAP values
|
87 |
-
explainer = shap.Explainer(model, input_val)
|
88 |
-
shap_values = explainer(input_val)
|
89 |
-
|
90 |
-
st_shap(shap.plots.waterfall(shap_values[0]), height=300)
|
91 |
-
st_shap(shap.plots.beeswarm(shap_values), height=300)
|
92 |
|
93 |
# shap_values = shap.TreeExplainer(model,feature_perturbation="tree_path_dependent").shap_values(X)
|
94 |
# st_shap(shap.force_plot(explainer.expected_value, shap_values[0,:], X_display.iloc[0,:]), height=200, width=1000)
|
|
|
6 |
import lightgbm as lgb
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
|
11 |
|
12 |
@st.experimental_memo
|
|
|
64 |
|
65 |
input_val = buil_UI(X)
|
66 |
|
67 |
+
if st.button('Calculate House Price'):
|
68 |
+
predictLGBM = best_model.predict(input_val)
|
69 |
+
submissionLGBM = pd.DataFrame({'SalePrice':predictLGBM})
|
70 |
+
result = submissionLGBM.iloc[0].values
|
71 |
+
st.write(result.astype(str))
|
72 |
+
|
73 |
+
shap_values = shap.TreeExplainer(model).shap_values(input_val)
|
74 |
+
st_shap(shap.plots.beeswarm(shap_values), height=300)
|
75 |
+
fig_summary = shap.summary_plot(shap_values, input_val)
|
76 |
+
st.pyplot(fig_summary)
|
77 |
+
|
78 |
+
shap_interaction_values = shap.TreeExplainer(model).shap_interaction_values(input_val.iloc[:,:])
|
79 |
+
st_shap(shap.summary_plot(shap_interaction_values, input_val.iloc[:,:]), height=400)
|
80 |
+
interaction_fig = shap.summary_plot(shap_interaction_values, input_val.iloc[:,:], height=400)
|
81 |
+
st.pyplot(interaction_fig)
|
82 |
+
|
83 |
+
# compute SHAP values
|
84 |
+
# explainer = shap.Explainer(model, input_val)
|
85 |
+
# shap_values = explainer(input_val)
|
86 |
+
|
87 |
+
# st_shap(shap.plots.waterfall(shap_values[0]), height=300)
|
88 |
+
# st_shap(shap.plots.beeswarm(shap_values), height=300)
|
89 |
+
|
90 |
+
|
91 |
+
# shap_interaction_values = shap.TreeExplainer(model).shap_interaction_values(input_val.iloc[:,:])
|
92 |
+
# shap.summary_plot(shap_interaction_values, input_val.iloc[:,:])
|
93 |
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# shap_values = shap.TreeExplainer(model,feature_perturbation="tree_path_dependent").shap_values(X)
|
97 |
# st_shap(shap.force_plot(explainer.expected_value, shap_values[0,:], X_display.iloc[0,:]), height=200, width=1000)
|