{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Google colab link:\n",
"\n",
"[https://colab.research.google.com/github/oegedijk/explainerdashboard/blob/master/custom_examples.ipynb](https://colab.research.google.com/github/oegedijk/explainerdashboard/blob/master/custom_examples.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"uncomment to install explainerdashboard:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2021-01-20T16:17:23.055000Z",
"start_time": "2021-01-20T16:17:23.050915Z"
}
},
"outputs": [],
"source": [
"#!pip install explainerdashboard"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# notebook properties:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2021-01-20T16:17:24.297328Z",
"start_time": "2021-01-20T16:17:24.292798Z"
}
},
"outputs": [],
"source": [
"from IPython.core.interactiveshell import InteractiveShell\n",
"\n",
"InteractiveShell.ast_node_interactivity = \"all\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2021-01-20T16:17:56.270605Z",
"start_time": "2021-01-20T16:17:52.395582Z"
}
},
"outputs": [],
"source": [
"from sklearn.ensemble import RandomForestClassifier\n",
"\n",
"from jupyter_dash import JupyterDash\n",
"\n",
"from explainerdashboard import *\n",
"from explainerdashboard.datasets import *\n",
"from explainerdashboard.custom import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# train model and build explainer"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2021-01-20T16:18:40.518834Z",
"start_time": "2021-01-20T16:18:39.584750Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: shap=='guess' so guessing for RandomForestClassifier shap='tree'...\n",
"Detected RandomForestClassifier model: Changing class type to RandomForestClassifierExplainer...\n",
"Note: model_output=='probability', so assuming that raw shap output of RandomForestClassifier is in probability space...\n",
"Generating self.shap_explainer = shap.TreeExplainer(model)\n",
"Calculating shap values...\n"
]
},
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hoverinfo": "skip",
"marker": {
"color": "rgba(1,1,1, 0.0)"
},
"name": "",
"type": "bar",
"x": [
"Population
average",
"Sex",
"Fare",
"PassengerClass",
"Deck",
"Embarked",
"No_of_parents_plus_children_on_board",
"No_of_siblings_plus_spouses_on_board",
"Age",
"Other features combined",
"Final Prediction"
],
"y": [
0,
39.26,
66.81,
75.81,
84.24,
91.12,
95.89,
97.92,
99.79,
98,
0
]
},
{
"hoverinfo": "text",
"marker": {
"color": [
"rgba(230, 230, 30, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(50, 200, 50, 1.0)",
"rgba(219, 64, 82, 0.7)",
"rgba(219, 64, 82, 0.7)",
"rgba(55, 128, 191, 0.7)"
],
"line": {
"color": [
"rgba(190, 190, 30, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(40, 160, 50, 1.0)",
"rgba(219, 64, 82, 1.0)",
"rgba(219, 64, 82, 1.0)",
"rgba(55, 128, 191, 1.0)"
],
"width": 2
}
},
"name": "contribution",
"text": [
"Population
average=
+39.26 ",
"Sex=female
+27.56 ",
"Fare=71.2833
+9.0 ",
"PassengerClass=1
+8.42 ",
"Deck=C
+6.88 ",
"Embarked=Cherbourg
+4.77 ",
"No_of_parents_plus_children_on_board=0
+2.03 ",
"No_of_siblings_plus_spouses_on_board=1
+1.87 ",
"Age=38.0
-1.79 ",
"Other features combined=
0.0 ",
"Final Prediction=
+98.0 "
],
"type": "bar",
"x": [
"Population
average",
"Sex",
"Fare",
"PassengerClass",
"Deck",
"Embarked",
"No_of_parents_plus_children_on_board",
"No_of_siblings_plus_spouses_on_board",
"Age",
"Other features combined",
"Final Prediction"
],
"y": [
39.26,
27.56,
9,
8.42,
6.88,
4.77,
2.03,
1.87,
-1.79,
0,
98
]
}
],
"layout": {
"barmode": "stack",
"height": 600,
"margin": {
"b": 216,
"l": 50,
"pad": 4,
"r": 100,
"t": 50
},
"plot_bgcolor": "#fff",
"showlegend": false,
"template": {
"data": {
"scatter": [
{
"type": "scatter"
}
]
}
},
"title": {
"text": "Contribution to prediction probability = 98.0%",
"x": 0.5
},
"yaxis": {
"range": [
0,
100
],
"title": {
"text": "Predicted %"
}
}
}
},
"text/html": [
"