wildboar.explain._importance#

Module Contents#

Classes#

AmplitudeImportance

Compute the importance of equi-probable horizontal time series intervals by

IntervalImportance

Compute a model agnostic importance score for non-overlapping intervals

PermuteImportance

Base class for all estimators in scikit-learn.

ShapeletImportance

Compute the importance of shapelets by permuting instances with lowest distance.

Functions#

plot_importances(importances[, ax, labels])

Plot the importances as a boxplot.

Attributes#

class wildboar.explain._importance.AmplitudeImportance(scoring=None, n_intervals='sqrt', window=None, binning='normal', n_bins=4, n_repeat=1, random_state=None)[source]#

Bases: wildboar.base.ExplainerMixin, PermuteImportance

Compute the importance of equi-probable horizontal time series intervals by permuting the values between each horizontal interval. The implementation uses transform.SAX to discretize the time series and then for each bin permute the samples along that bin.

Paramters#

sax_SAX

The SAX transformation.

baseline_score_float or dict

The baseline score.

importances_float or dict

The importances of each vertical bin.

components_list

List of binning identifiers.

fit(estimator, X, y, sample_weight=None)[source]#
plot(x=None, y=None, *, ax=None, n_samples=100, scoring=None, preprocess=True, k=None, show_bins=False, show_grid=True)[source]#

Plot the importances. If x is given, the importances are plotted over the samples optionally labeling each sample using the supplied labels. If x is not give, the importances are plotted as one or more boxplots.

Parameters:
  • x (array-like of shape (n_samples, n_timesteps), optional) – The samples

  • y (array-like of shape (n_samples, ), optional) – The labels

  • ax (Axes, optional) – Axes to plot. If ax is set, x is None and scoring is None, the number of axes must be the same as the number of scorers.

  • scoring (str, optional) – The scoring to plot if multiple scorers were used when fitting.

  • preprocess (bool, optional) – Preprocess the time series to align with the bins, ignored if x is not None.

  • k (int or float, optional) –

    The number of top bins to plot, ignored if x is not None.

    • if int, the specified number of bins are shown

    • if float, a fraction of the number of bins are shown

  • show_bins (bool, optional) – Annotate the plot with the index of the bin, ignored if x is not None.

  • show_grid (bool, optional) – Annotate the plot with the bin thresholds, ignored if x is not None.

Returns:

  • ax (Axis) – The axis

  • mappable (ScalarMappable, optional) – Return the mappable used to plot the colorbar. Only returned if ax is not None and x is not None.

class wildboar.explain._importance.IntervalImportance(*, scoring=None, n_repeat=5, n_intervals='sqrt', window=None, verbose=False, random_state=None)[source]#

Bases: wildboar.base.ExplainerMixin, PermuteImportance

Compute a model agnostic importance score for non-overlapping intervals

importances_[source]#

The importance scores for each interval. If dict, one value per scoring function.

Type:

dict or Importance

components_[source]#

The interval start and end positions.

Type:

ndarray of shape (n_intervals, 2)

Parameters:
  • scoring (str, list, dict or callable, optional) – The scoring function. By default the estimators score function is used.

  • n_repeat (int, optional) – The number of repeated permutations

  • n_intervals (str, optional) –

    The number of intervals.

    • if “sqrt”, the number of intervals is the square root of n_timestep.

    • if “log”, the number of intervals is the log2 of n_timestep.

    • if int, exact number of intervals.

  • window (int, optional) – The window size. If specicied, n_intervals is ignored and the number of intervals is computed such that each interval is (at least) of size window.

  • domain ({"time", "frequency"}, optional) – Compute the importance in the time or frequency domain.

  • verbose (bool, optional) – Show extra progress information.

  • random_state (int or RandomState) –

    • If int, random_state is the seed used by the random number generator

    • If RandomState instance, random_state is the random number generator

    • If None, the random number generator is the RandomState instance used by np.random.

explain(x, y=None)[source]#
fit(estimator, x, y, sample_weight=None)[source]#
plot(x=None, y=None, *, ax=None, scoring=None, k=None, n_samples=100, show_grid=True)[source]#

Plot the explanation.

Returns:

ax – The axes object

Return type:

Axes

class wildboar.explain._importance.PermuteImportance(*, scoring=None, n_repeat=1, verbose=0, random_state=None)[source]#

Bases: wildboar.base.BaseEstimator

Base class for all estimators in scikit-learn.

Notes

All estimators should specify all the parameters that can be set at the class level in their __init__ as explicit keyword arguments (no *args or **kwargs).

class wildboar.explain._importance.ShapeletImportance(scoring=None, n_repeat=1, n_shapelets=10, min_shapelet_size=0.0, max_shapelet_size=1.0, metric='euclidean', metric_params=None, random_state=None)[source]#

Bases: wildboar.base.ExplainerMixin, PermuteImportance

Compute the importance of shapelets by permuting instances with lowest distance.

components[source]#

The shapelets

Type:

ndarray

explain(X, y=None, kernel_scale=0.25)[source]#
fit(estimator, X, y, sample_weight=None)[source]#
plot(X=None, y=None, k=None, scoring=None, kernel_scale=0.25, ax=None)[source]#

Plot the explanation.

Returns:

ax – The axes object

Return type:

Axes

wildboar.explain._importance.plot_importances(importances, ax=None, labels=None)[source]#

Plot the importances as a boxplot.

Paramters#

importancesImportance or dict

The importances

axAxes, optional

The axes to plot. If importances is dict, ax must contain at least len(importances) Axes objects.

labelsarray-like, optional

The labels for the importances.

returns:

ax – The plotted Axes.

rtype:

Axes

wildboar.explain._importance.Importance[source]#
wildboar.explain._importance.matplotlib_missing[source]#