omnixai.explanations.timeseries package

feature_importance

Feature importance explanations for time series tasks.

counterfactual

Counterfactual explanations for time series tasks.

omnixai.explanations.timeseries.feature_importance module

Feature importance explanations for time series tasks.

class omnixai.explanations.timeseries.feature_importance.FeatureImportance(mode, explanations=None)

Bases: ExplanationBase

The class for feature importance explanations for time series tasks. It uses a list to store the feature importance explanations of the input instances. Each item in the list is a dict with the following format {“instance”: the input instance, “scores”: feature importance scores}, where both “instance” and “scores” are pandas dataframes.

Parameters
  • mode – The task type, e.g., anomaly_detection or forecasting.

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

add(instance, importance_scores, **kwargs)

Adds the generated explanation corresponding to one instance.

Parameters
  • instance – The instance to explain.

  • importance_scores – The feature importance scores.

get_explanations(index=None)

Gets the generated explanations.

Parameters

index – The index of an explanation result stored in FeatureImportance. 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, “scores”: feature importance scores}, where both “instance” and “scores” are pandas dataframes.

Return type

Union[Dict, List]

plot(index=None, figure_type=None, max_num_variables_to_plot=25, **kwargs)

Plots importance scores for time series data.

Parameters
  • index – The index of an explanation result stored in FeatureImportance, e.g., it will plot the first explanation result when index = 0. When index is None, it plots all the explanations.

  • figure_type – The figure type, e.g., plotting importance scores in a timeseries or a bar.

  • max_num_variables_to_plot – The maximum number of variables to plot in the figure.

Returns

A matplotlib figure plotting feature importance scores.

plotly_plot(index=0, **kwargs)

Plots feature importance scores for one specific instance using Dash.

Parameters

index – The index of an explanation result stored in FeatureImportance which cannot be None, e.g., it will plot the first explanation result when index = 0.

Returns

A plotly dash figure plotting feature importance scores.

ipython_plot(index=0, **kwargs)

Plots the feature importance scores in IPython.

Parameters

index – The index of an explanation result stored in FeatureImportance, which cannot be None, e.g., it will plot the first explanation result when index = 0.

to_json()

Converts the explanation result into JSON format.

classmethod from_dict(d)

omnixai.explanations.timeseries.counterfactual module

Counterfactual explanations for time series tasks.

class omnixai.explanations.timeseries.counterfactual.CFExplanation

Bases: ExplanationBase

The class for counterfactual explanations for time series tasks. It uses a list to store the counterfactual examples of the input instances. Each item in the list is a dict with the following format {“query”: the input instance, “counterfactual”: the generated counterfactual example}. Both “query” and “counterfactual” are pandas dataframes.

add(query, cfs, **kwargs)

Adds the generated explanation corresponding to one instance.

Parameters
  • query – The instance to explain.

  • cfs – The generated counterfactual examples.

  • kwargs – Additional information to store.

get_explanations(index=None)

Gets the generated counterfactual explanations.

Parameters

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

Returns

The explanation for one specific instance (a dict) or all the explanations for all the instances (a list). Each dict has the following format: {“query”: the original input instance, “counterfactual”: the generated counterfactual examples}. Both “query” and “counterfactual” are pandas dataframes.

Return type

Union[Dict, List]

plot(index=None, max_num_variables_to_plot=25, **kwargs)

Plots counterfactual examples for time series data.

Parameters
  • index – The index of an explanation result stored in CFExplanation, e.g., it will plot the first explanation result when index = 0. When index is None, it plots all the explanations.

  • max_num_variables_to_plot – The maximum number of variables to plot in the figure.

Returns

A matplotlib figure plotting counterfactual examples.

plotly_plot(index=0, **kwargs)

Plots counterfactual examples for one specific instance using Dash.

Parameters

index – The index of an explanation result stored in CFExplanation which cannot be None, e.g., it will plot the first explanation result when index = 0.

Returns

A plotly dash figure plotting counterfactual examples.

ipython_plot(index=0, **kwargs)

Plots counterfactual examples in IPython.

Parameters

index – The index of an explanation result stored in CFExplanation, which cannot be None, e.g., it will plot the first explanation result when index = 0.

to_json()

Converts the explanation result into JSON format.

classmethod from_dict(d)