Visualizations#
The visualizations that power interpret
use different renderers depending on the environment they are in. In most cases, the package will detect what kind of environment it is in and use the appropriat renderer. There are times though when you want to forcefully select which one.
Dash Renderer
The Dash renderer is used for local environments such as running a Jupyter notebook on your laptop. It runs a Dash server, backed by Apache Flask in a separate process the first time its called by interpret
.
This provides access to both embedded visualizations within notebooks as well as the full dashboard. However, due to requiring a live Flask server, it cannot render in an offline notebook.
See the source code for underestandings its configuration here.
from interpret import set_visualize_provider
from interpret.provider import DashProvider
set_visualize_provider(DashProvider.from_address(('127.0.0.1', 7001)))
- class interpret.provider.DashProvider(app_runner)#
Provides rendering via Plotly’s Dash.
This works in the event of an environment that can expose HTTP(s) ports.
Initializes class.
This requires an instantiated AppRunner, call .from_address instead to initialize both.
- Parameters:
app_runner – An AppRunner instance.
- classmethod from_address(addr=None, base_url=None, use_relative_links=False)#
Initialize a new AppRunner along with the provider.
- Parameters:
addr – A tuple that is (ip_addr, port).
base_url – Base URL, this useful when behind a proxy.
use_relative_links – Relative links for rendered pages instead of full URI.
Inline Renderer
The inline renderer is used for cloud environments access to flask servers are not always available. In most configurations, it injects JavaScript in each notebook cell, including the bundle.
This does not allow for full dashboards, but it does allow offline support.
See the source code for underestandings its configuration here.
from interpret import set_visualize_provider
from interpret.provider import InlineProvider
set_visualize_provider(InlineProvider())
- class interpret.provider.InlineProvider(detected_envs=None, js_url=None)#
Provides rendering via JavaScript that are invoked within Jupyter cells.
Initializes class.
- Parameters:
detected_envs – Environments targetted as defined in interpret.utils.environment.
js_url – If defined, will load the JavaScript bundle for interpret-inline from the given URL.
Interactivity
The visualizations consume the Interpret API, and is responsible for both displaying explanations and the underlying rendering infrastructure.
Visualizing with the show method
Interpret exposes a top-level method show
, of which acts as the surface for rendering explanation visualizations. This can produce either a drop down widget or dashboard depending on what’s provided.
Show a single explanation
For basic use cases, it is good to show an explanation one at a time. The rendered widget will provide a dropdown to select between visualizations. For example, in the event of a global explanation, it will provide an overview, along with graphs for each feature as shown with the code below:
from interpret import set_visualize_provider
from interpret.provider import InlineProvider
set_visualize_provider(InlineProvider())
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from interpret.glassbox import ExplainableBoostingClassifier
from interpret import show
df = pd.read_csv(
"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",
header=None)
df.columns = [
"Age", "WorkClass", "fnlwgt", "Education", "EducationNum",
"MaritalStatus", "Occupation", "Relationship", "Race", "Gender",
"CapitalGain", "CapitalLoss", "HoursPerWeek", "NativeCountry", "Income"
]
X = df.iloc[:, :-1]
y = (df.iloc[:, -1] == " >50K").astype(int)
seed = 42
np.random.seed(seed)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=seed)
ebm = ExplainableBoostingClassifier()
ebm.fit(X_train, y_train)
ExplainableBoostingClassifier()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
ExplainableBoostingClassifier()
ebm_global = ebm.explain_global()
show(ebm_global)