Skip to content

Commit d2dcaf9

Browse files
committed
errors in summary plot fixed
1 parent 07887a2 commit d2dcaf9

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed
0 Bytes
Binary file not shown.

lib/plotly_graphs.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
from shap_pdp import *
55
from summary_plot import *
66
from data_for_shap_graphs import *
7+
import plotly.graph_objects as go
8+
79

810
class plotly_graphs():
911
def __init__(self):
1012
super(plotly_graphs, self).__init__()
11-
self.data= data_for_shap_graphs()
13+
self.data = data_for_shap_graphs()
1214

1315
# save all important variables here.
1416

15-
16-
def feature_importance(self, df):
17+
def feature_importance(self, df):
1718
df2 = self.data.feature_importance(df)
1819

1920
names = list(df2["VariableName"])
@@ -24,7 +25,8 @@ def feature_importance(self, df):
2425

2526
df2["VariableName"] = new_names
2627

27-
feature_importance = px.bar(df2, x='Impact_Value', y="VariableName", orientation='h', title='Feature Importance',)
28+
feature_importance = px.bar(df2, x='Impact_Value', y="VariableName", orientation='h',
29+
title='Feature Importance', )
2830
return feature_importance, df2
2931

3032
def feature_impact(self, df):
@@ -45,21 +47,31 @@ def feature_impact(self, df):
4547

4648
def summary_plot(self, df):
4749
df2 = self.data.summary_plot(df)
50+
# summary_plot = go.Figure()
51+
4852

53+
# summary_plot.add_trace(go.Scattergl(x=df2['xaxis'], y=df2['yaxis'],
54+
# mode='markers',hovertext=df2['hover'],
55+
# marker=dict(color=list(df2['color']),showscale=True,autocolorscale=False,
56+
# cauto=False)))
4957
summary_plot = px.scatter(df2, x="xaxis", y="yaxis", color="color", hover_data=["hover"])
5058

5159
return summary_plot, df2
5260

5361
def partial_dependence_plot(self, df, v1, v2, v3):
5462
pdp = shap_pdp()
5563
df = pdp.find(df)
56-
g= px.scatter(df, x=v1, y=v2, color=v3)
64+
g = go.Figure()
65+
print("new")
66+
# g.add_trace(go.Scattergl(x=df[v1], y=df[v2], mode='markers',showlegend=True,
67+
# marker=dict(color=list(df[v3]),
68+
# autocolorscale=False,
69+
# cauto=False
70+
# )))
71+
72+
g = px.scatter(df, x=v1, y=v2, color=v3)
5773
return g, df
5874

59-
6075
def distributions(self, df, variable_name):
61-
graph= px.histogram(df, x=variable_name, marginal="box")
76+
graph = px.histogram(df, x=variable_name, marginal="box")
6277
return graph
63-
64-
65-

lib/rescale_numeric_feature.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ def add_col_rescaled(self, df):
9999

100100
for nc in numeric_columns:
101101
# get min and max
102-
mini, maxi = self.get_min_max(df_describe, nc)
102+
if nc in df_describe:
103+
mini, maxi = self.get_min_max(df_describe, nc)
103104

104-
df[nc + "_rescaled"] = (df[nc] - mini) / (maxi - mini) * 10
105+
df[nc + "_rescaled"] = (df[nc] - mini) / (maxi - mini) * 10
105106

106107
for cc in categorical_columns:
107108
df[cc + "_rescaled"] = 0

lib/summary_plot.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ def rearrange_dataframe(self, df_re ):
3333
df_final = pd.DataFrame()
3434

3535
for v in self.original_columns:
36-
df_single = df_re[[v, v + '_rescaled', v + '_impact']]
37-
df_single["variable_name"] = v
38-
df_single.columns = ['hover', 'color', 'xaxis', 'yaxis']
39-
df_final = pd.concat([df_final, df_single])
40-
36+
try:
37+
df_single = df_re[[v, v + '_rescaled', v + '_impact']]
38+
df_single["variable_name"] = v
39+
df_single.columns = ['hover', 'color', 'xaxis', 'yaxis']
40+
df_final = pd.concat([df_final, df_single])
41+
except Exception as e:
42+
pass
4143
return df_final
4244

4345

0 commit comments

Comments
 (0)