omnixai.explanations package

This package contains the classes for explanation results. All of these classes provide plotting functions for visualization, e.g.,

  • plot: Using Matplotlib to plot figures for visualizing explanation results.

  • plotly_plot: Using Plotly Dash to plot figures for visualizing explanation results.

  • ipython_plot: Showing explanation results in IPython.

Three categories of explanation results

omnixai.explanations.base module

class omnixai.explanations.base.ExplanationBase

Bases: object

Abstract base class for explanation results.

abstract get_explanations(**kwargs)

Gets the generated explanations.

Returns

A dict or a list containing the explanations.

abstract plot(**kwargs)

Returns a matplotlib figure showing the explanations.

Returns

A matplotlib figure.

abstract plotly_plot(**kwargs)

Returns a plotly dash component showing the explanations.

Returns

A plotly dash component.

abstract ipython_plot(**kwargs)

Plots figures in IPython.

dump(file)

Pickles an explanation object to a file.

load(file)

Unpickle an explanation object from a file.

dumps()

Pickles a explanation object into a byte string. :return: The pickled explanation object.

loads(byte_string)

Loads an explanation object from a byte string.

Parameters

byte_string – A byte string.

Returns

The loaded explanation object.

to_json()

Converts the explanation result into JSON format.

classmethod from_json(s)

Loads the explanation result from a JSON input. :type s: :param s: The input in JSON format. :return: The loaded explanation object.

classmethod from_dict(d)
class omnixai.explanations.base.DashFigure(component)

Bases: object

show(**kwargs)
to_html_div(id=None)
to_html()
class omnixai.explanations.base.PredictedResults(predictions=None)

Bases: ExplanationBase

The class for prediction results.

Parameters

predictions – For classfication, predictions are the predicted class probabilities. For regression, predictions are the predicted values.

get_explanations()

Gets the prediction results.

Returns

The prediction results.

Return type

Dict

plot(index=None, class_names=None, max_num_subplots=4, **kwargs)

Returns a matplotlib figure showing the predictions.

Parameters
  • index – The index of the instance. When it is None, it returns a figure with max_num_subplots subplots where each subplot plots the feature importance scores for one instance.

  • class_names – The class names.

  • max_num_subplots – The maximum number of subplots in the figure.

Returns

A matplotlib figure plotting the predictions.

plotly_plot(index, class_names=None, **kwargs)

Returns a plotly dash figure showing the predictions for one specific instance.

Parameters
  • index – The index of the instance which cannot be None.

  • class_names – The class names.

Returns

A plotly dash figure plotting the predictions.

ipython_plot(index, class_names=None, **kwargs)

Plots prediction results in IPython.

Parameters
  • index – The index of the instance which cannot be None.

  • class_names – The class names.

classmethod from_dict(d)
class omnixai.explanations.base.PlainText(explanations=None)

Bases: ExplanationBase

The class for plain text explanations.

Parameters

explanations – The explanation results for initializing FeatureImportance, which is optional.

add(instance, text, **kwargs)

Adds the generated explanation corresponding to one instance.

Parameters
  • instance – The instance to explain.

  • text – The text explanation of the given instance.

get_explanations(index=None)

Gets the generated explanations.

Parameters

index – The index of an explanation result stored in PlainText. When index is None, the function returns a list of all the explanations.

Returns

The explanation for one specific instance (a dict) or the explanations for all the instances (a list of dicts). Each dict has the following format: {“instance”: the input instance, “text”: the corresponding explanations in plain text}.

Return type

Union[Dict, List]

plot(**kwargs)

Returns a matplotlib figure showing the explanations.

Returns

A matplotlib figure.

plotly_plot(**kwargs)

Returns a plotly dash component showing the explanations.

Returns

A plotly dash component.

ipython_plot(**kwargs)

Plots figures in IPython.

classmethod from_dict(d)