Skip to content

Commit

Permalink
errors in summary plot fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ms8909 committed Jun 24, 2020
1 parent 07887a2 commit d2dcaf9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
Binary file modified lib/__pycache__/calculate_shap.cpython-37.pyc
Binary file not shown.
32 changes: 22 additions & 10 deletions lib/plotly_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
from shap_pdp import *
from summary_plot import *
from data_for_shap_graphs import *
import plotly.graph_objects as go


class plotly_graphs():
def __init__(self):
super(plotly_graphs, self).__init__()
self.data= data_for_shap_graphs()
self.data = data_for_shap_graphs()

# save all important variables here.


def feature_importance(self, df):
def feature_importance(self, df):
df2 = self.data.feature_importance(df)

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

df2["VariableName"] = new_names

feature_importance = px.bar(df2, x='Impact_Value', y="VariableName", orientation='h', title='Feature Importance',)
feature_importance = px.bar(df2, x='Impact_Value', y="VariableName", orientation='h',
title='Feature Importance', )
return feature_importance, df2

def feature_impact(self, df):
Expand All @@ -45,21 +47,31 @@ def feature_impact(self, df):

def summary_plot(self, df):
df2 = self.data.summary_plot(df)
# summary_plot = go.Figure()


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

return summary_plot, df2

def partial_dependence_plot(self, df, v1, v2, v3):
pdp = shap_pdp()
df = pdp.find(df)
g= px.scatter(df, x=v1, y=v2, color=v3)
g = go.Figure()
print("new")
# g.add_trace(go.Scattergl(x=df[v1], y=df[v2], mode='markers',showlegend=True,
# marker=dict(color=list(df[v3]),
# autocolorscale=False,
# cauto=False
# )))

g = px.scatter(df, x=v1, y=v2, color=v3)
return g, df


def distributions(self, df, variable_name):
graph= px.histogram(df, x=variable_name, marginal="box")
graph = px.histogram(df, x=variable_name, marginal="box")
return graph



5 changes: 3 additions & 2 deletions lib/rescale_numeric_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def add_col_rescaled(self, df):

for nc in numeric_columns:
# get min and max
mini, maxi = self.get_min_max(df_describe, nc)
if nc in df_describe:
mini, maxi = self.get_min_max(df_describe, nc)

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

for cc in categorical_columns:
df[cc + "_rescaled"] = 0
Expand Down
12 changes: 7 additions & 5 deletions lib/summary_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ def rearrange_dataframe(self, df_re ):
df_final = pd.DataFrame()

for v in self.original_columns:
df_single = df_re[[v, v + '_rescaled', v + '_impact']]
df_single["variable_name"] = v
df_single.columns = ['hover', 'color', 'xaxis', 'yaxis']
df_final = pd.concat([df_final, df_single])

try:
df_single = df_re[[v, v + '_rescaled', v + '_impact']]
df_single["variable_name"] = v
df_single.columns = ['hover', 'color', 'xaxis', 'yaxis']
df_final = pd.concat([df_final, df_single])
except Exception as e:
pass
return df_final


Expand Down

0 comments on commit d2dcaf9

Please sign in to comment.