Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
  • Loading branch information
Oege Dijk authored and Oege Dijk committed Dec 20, 2019
1 parent 38fdd98 commit abba45d
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 105 deletions.
154 changes: 103 additions & 51 deletions dashboard_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-06T13:04:08.094300Z",
"start_time": "2019-11-06T13:04:07.767281Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
Expand Down Expand Up @@ -195,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-06T13:03:52.617314Z",
Expand All @@ -216,7 +207,7 @@
" verbose=0, warm_start=False)"
]
},
"execution_count": 13,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -244,44 +235,45 @@
"output_type": "stream",
"text": [
" * Running on http://127.0.0.1:8052/ (Press CTRL+C to quit)\n",
"127.0.0.1 - - [18/Dec/2019 14:35:22] \"GET / HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:23] \"GET /_dash-layout HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:23] \"GET /_dash-dependencies HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:23] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:23] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:24] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:25] \"GET /_dash-component-suites/dash_table/async~table.v4_5_1m1573762302.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:26] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:26] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:27] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:27] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:27] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:29] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:29] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:31] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:31] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:32] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:33] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:34] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:34] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:35] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:35] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:35] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:37] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:37] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:37] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:35:38] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:36:58] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:37:01] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [18/Dec/2019 14:37:08] \"POST /_dash-update-component HTTP/1.1\" 200 -\n"
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"GET / HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"GET /_dash-dependencies HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"GET /_dash-layout HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:30] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:31] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:31] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:31] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:32] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:34] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:34] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:34] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:34] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:34] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:39] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:39] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:42] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:42] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:42] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:42] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:43] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:44] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:44] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:44] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:45] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:45] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:45] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:45] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:46] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:46] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:47] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:47] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:47] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 11:56:48] \"POST /_dash-update-component HTTP/1.1\" 200 -\n"
]
}
],
Expand All @@ -307,6 +299,66 @@
"db.run(8052)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running Model Explainer on http://localhost:8052\n",
" * Serving Flask app \"explainerdashboard.dashboards\" (lazy loading)\n",
" * Environment: production\n",
" WARNING: This is a development server. Do not use it in a production deployment.\n",
" Use a production WSGI server instead.\n",
" * Debug mode: off\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" * Running on http://127.0.0.1:8052/ (Press CTRL+C to quit)\n",
"127.0.0.1 - - [20/Dec/2019 12:06:52] \"GET / HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"GET /_dash-layout HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"GET /_dash-dependencies HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:53] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:54] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:55] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:56] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:56] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:56] \"POST /_dash-update-component HTTP/1.1\" 204 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:56] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:57] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:06:59] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:07:00] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:07:01] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:07:02] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:07:04] \"POST /_dash-update-component HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [20/Dec/2019 12:07:05] \"POST /_dash-update-component HTTP/1.1\" 200 -\n"
]
}
],
"source": [
"db = ExplainerDashboard(explainer,\n",
" model_summary=True,\n",
" contributions=True,\n",
" shap_dependence=True,\n",
" shap_interaction=True,\n",
" shadow_trees=True)\n",
"db.run(8052)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
55 changes: 28 additions & 27 deletions explainerdashboard/dashboard_tabs/model_summary_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ def layout(self):
className="mr-1",
),
], justify="center"),
html.Div([
dbc.Row([
dbc.Col([
dbc.FormGroup([
dbc.RadioButton(
id="lift-curve-percentage", className="form-check-input"
),
dbc.Label(
"Display percentages",
html_for="lift-curve-percentage",
className="form-check-label",
),
], check=True),
], width=2),
], justify="end",),
dbc.Row([
dbc.Col([
html.Div([
dcc.Loading(id="loading-lift-curve",
children=[dcc.Graph(id='lift-curve-graph')]),
], style={'margin': 20}),
]),
]),
], id='lift-curve-div', style={}), # style={'display': 'none'}),
html.Div([
dbc.Row([
dbc.Col([
Expand Down Expand Up @@ -190,33 +214,10 @@ def layout(self):
dcc.Loading(id="loading-precision-graph",
children=[dcc.Graph(id='precision-graph')]),
], style={'margin': 20}),
]),
]),
], id='precision-plot-div', style={'display': 'none'}),
html.Div([
dbc.Row([
dbc.Col([
dbc.FormGroup([
dbc.RadioButton(
id="lift-curve-percentage", className="form-check-input"
),
dbc.Label(
"Display percentages",
html_for="lift-curve-percentage",
className="form-check-label",
),
], check=True),
], width=2),
], justify="end",),
dbc.Row([
dbc.Col([
html.Div([
dcc.Loading(id="loading-lift-curve",
children=[dcc.Graph(id='lift-curve-graph')]),
], style={'margin': 20}),
]),
]),
], id='lift-curve-div', style={'display': 'none'}),
], width=12),
], align="center"),
], id='precision-plot-div', style={}), #{'display': 'none'}),

dbc.Row([
dbc.Col([
html.Div([
Expand Down
33 changes: 7 additions & 26 deletions explainerdashboard/explainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .explainer_plots import *



class BaseExplainerBunch(ABC):
"""Abstract Base Class. Defines the basic functionality of an ExplainerBunch
But does not yet have a defined shap_explainer.
Expand Down Expand Up @@ -779,8 +778,6 @@ def plot_pdp(self, col, index=None, drop_na=True, sample=100,
num_grid_lines=min(num_grid_lines, sample, len(self.X)))




class TreeExplainerBunch(BaseExplainerBunch):
"""Defines an explainer bunch for tree based models (random forests, xgboost,etc).
Expand Down Expand Up @@ -888,7 +885,7 @@ def plot_trees(self, index, round=2):
return plotly_tree_predictions(self.model, self.X.iloc[[idx]], round)

def calculate_properties(self, include_interactions=True):
_ = (self.shadow_trees)
_ = self.shadow_trees
super().calculate_properties(include_interactions)


Expand Down Expand Up @@ -1181,6 +1178,7 @@ def plot_pr_auc(self, cutoff=0.5):
return plotly_pr_auc_curve(self.y_binary, self.pred_probas, cutoff=cutoff)

def calculate_properties(self, include_interactions=True):
_ = self.pred_probas
super().calculate_properties(include_interactions)


Expand Down Expand Up @@ -1224,85 +1222,68 @@ def plot_residuals_vs_feature(self, col, vs_actual=False, round=2, ratio=False):
return plotly_residuals_vs_col(explainer.y, explainer.preds, explainer.X[col],
vs_actual=vs_actual, units=self.units, round=round, ratio=ratio)

def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class TreeClassifierBunch(TreeExplainerBunch, ClassifierBunch):
"""TreeModelClassifierBunch inherits from both TreeModelBunch and
ClassifierBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class DeepClassifierBunch(DeepExplainerBunch, ClassifierBunch):
"""DeepClassifierBunch inherits from both DeepExplainerBunch and
ClassifierBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class LinearClassifierBunch(LinearExplainerBunch, ClassifierBunch):
"""LinearClassifierBunch inherits from both LinearExplainerBunch and
ClassifierBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class KernelClassifierBunch(KernelExplainerBunch, ClassifierBunch):
"""KernelClassifierBunch inherits from both KernelExplainerBunch and
ClassifierBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class RandomForestClassifierBunch(RandomForestExplainerBunch, ClassifierBunch):
"""RandomForestClassifierBunch inherits from both RandomForestBunch and
ClassifierBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class TreeRegressionBunch(TreeExplainerBunch, RegressionBunch):
"""TreeRegressionBunch inherits from both TreeExplainertBunch and
RegressionBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class LinearRegressionBunch(LinearExplainerBunch, RegressionBunch):
"""LinearRegressionBunch inherits from both LinearExplainerBunch and
RegressionBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)



class DeepRegressionBunch(DeepExplainerBunch, RegressionBunch):
"""DeepRegressionBunch inherits from both DeepExplainerBunch and
RegressionBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)



class KernelRegressionBunch(KernelExplainerBunch, RegressionBunch):
"""KernelRegressionBunch inherits from both KernelExplainerBunch and
RegressionBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)


class RandomForestRegressionBunch(RandomForestExplainerBunch, RegressionBunch):
"""RandomForestClassifierBunch inherits from both RandomForestBunch and
RegressionBunch.
"""
def calculate_properties(self, include_interactions=True):
super().calculate_properties(include_interactions)



2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='explainerdashboard',
version='0.1.7.1',
version='0.1.7.2',
description='package to ease and speed up machine learning model explainability',
long_description='explainerdashboard allows you quickly build an interactive dashboard to explain the inner workings of a machine learning model.',
license='MIT',
Expand Down

0 comments on commit abba45d

Please sign in to comment.