ShapeletClassifierVisualizer¶
- class ShapeletClassifierVisualizer(estimator)[source]¶
A class to visualize the result from a fitted shapelet classifier.
- Parameters:
- estimatorobject
A fitted shapelet classifier.
Methods
plot
(id_shapelet[, ax, scatter_options, ...])Plot the shapelet values.
plot_distance_vector
(id_shapelet, X[, ax, ...])Plot the shapelet distance vector computed between itself and X.
plot_on_X
(id_shapelet, X[, ax, ...])Plot the shapelet on its best match on the time series X.
visualize_shapelets_one_class
(X, y, class_id)Plot the n_shp best (or worst) candidates for the class_id.
- visualize_shapelets_one_class(X, y, class_id, best=True, n_shp=1, id_example_other=None, id_example_class=None, class_colors=('tab:green', 'tab:orange'), scatter_options={'alpha': 0.75, 'edgecolor': 'black', 'linewidths': 2, 's': 70, 'zorder': 1}, x_plot_options={'alpha': 0.9, 'linewidth': 4}, shp_plot_options={'alpha': 0.9, 'linestyle': '--', 'linewidth': 2}, dist_plot_options={'alpha': 0.9, 'linewidth': 3}, threshold_plot_options={'alpha': 0.9, 'color': 'purple', 'label': 'threshold', 'linewidth': 2}, boxplot_options={'boxprops': {'linewidth': 1.5}, 'flierprops': {'linewidth': 1.5}, 'meanline': True, 'meanprops': {'color': 'black', 'linewidth': 1.5}, 'medianprops': {'color': 'black', 'linewidth': 1.5}, 'patch_artist': True, 'showmeans': True, 'whiskerprops': {'linewidth': 1.5}, 'widths': 0.6}, figure_options={'dpi': 200, 'figsize': (20, 12), 'ncols': 3, 'nrows': 2}, rc_Params_options={'axes.labelsize': 15, 'axes.titlesize': 15, 'legend.fontsize': 14, 'xtick.labelsize': 13, 'ytick.labelsize': 13}, matplotlib_style='seaborn-v0_8')[source]¶
Plot the n_shp best (or worst) candidates for the class_id.
Visualize best match on two random samples and how the shapelet discriminate (X,y) with boxplots.
- Parameters:
- Xarray, shape=(n_samples, n_fetaures, n_timestamps)
A time series dataset. Can be the training set to visualize training results, or testing to visualize generalization to unseen samples.
- yarray, shape=(n_samples)
The true classes of the time series dataset.
- class_idint
ID of the class we want to visualize. The n_shp best shapelet for this class will be selected based on the feature coefficients inside the ridge classifier. The original labels are given to a LabelEncoder, hence why we ask for an integer ID.
- bestbool, optional
Specifies whether to return the best or the worst shapelet(s) for a class. The default is True, returning the best shapelet(s)
- n_shpint, optional
Number of plots to output, one per shapelet (i.e. the n_shp best shapelets for class_id). The default is 1.
- id_example_otherint
Sample ID to use for sample of other class. If None, a random one from that class is selected.
- id_example_classint
Sample ID to use for sample of class_id.If None, a random one from that class is selected.
- scatter_optionsdict
Dictionnary of options passed to the scatter plot of the shapelet values.
- x_plot_optionsdict
Dictionnary of options passed to the plot of the time series values.
- shp_plot_optionsdict
Dictionnary of options passed to the plot of the shapelet values.
- threshold_plot_optionsdict
Dictionnary of options passed to the line plot of the threshold.
- dist_plot_optionsdict
Dictionnary of options passed to the plot of the distance vector values.
- figure_optionsdict
Dictionnary of options passed to plt.figure.
- boxplot_optionsdict
Dictionnary of options passed to features boxplot.
- rc_Params_options: dict
Dictionnary of options passed to plt.rcParams.update.
- matplotlib_style: str
Matplotlib style to be used.
- Returns:
- figureslist of matplotlib figure
The resulting figures for each selected shapelets (list of size n_shp)
- plot_on_X(id_shapelet, X, ax=None, scatter_options={'alpha': 0.9, 'c': 'purple', 's': 40, 'zorder': 3}, line_options={'alpha': 0.9, 'linewidth': 2}, figure_options={'dpi': 100, 'figsize': (10, 5)}, rc_Params_options={'font.size': 22}, matplotlib_style='seaborn-v0_8')[source]¶
Plot the shapelet on its best match on the time series X.
- Parameters:
- id_shapeletint
ID of the shapelet to plot.
- Xarray, shape=(n_features, n_timestamps)
Input time series
- axmatplotlib axe
A matplotlib axe on which to plot the figure. The default is None and will create a new figure of size figsize.
- scatter_optionsdict
Dictionnary of options passed to the scatter plot of the shapelet values.
- line_optionsdict
Dictionnary of options passed to the plot of the time series values.
- figure_optionsdict
Dictionnary of options passed to plt.figure. Only used if ax is None.
- rc_Params_options: dict
Dictionnary of options passed to plt.rcParams.update. Only used if ax is None.
- matplotlib_style: str
Matplotlib style to be used. Only used if ax is None.
- Returns:
- figmatplotlib figure
The resulting figure with S on its best match on X. A normalised shapelet will be scalled to macth the scale of X.
- plot_distance_vector(id_shapelet, X, ax=None, show_legend=True, show_threshold=True, line_options={'alpha': 0.9, 'linewidth': 2}, threshold_options={'alpha': 0.9, 'color': 'purple', 'label': 'threshold', 'linewidth': 2}, figure_options={'dpi': 100, 'figsize': (10, 5)}, rc_Params_options={'font.size': 22}, matplotlib_style='seaborn-v0_8')[source]¶
Plot the shapelet distance vector computed between itself and X.
- Parameters:
- id_shapeletint
ID of the shapelet to plot.
- Xarray, shape=(n_timestamps) or shape=(n_features, n_timestamps)
Input time series
- axmatplotlib axe
A matplotlib axe on which to plot the figure. The default is None and will create a new figure of size figsize.
- show_legendbool, optional
Wheter to show legend. Default is True
- show_threshold: bool, optional
Wheter to show threshold (if it is not set to None). Default is True.
- threshold_plot_optionsdict
Dictionnary of options passed to the line plot of the threshold.
- dist_plot_optionsdict
Dictionnary of options passed to the plot of the distance vector values.
- figure_optionsdict
Dictionnary of options passed to plt.figure. Only used if ax is None.
- rc_Params_options: dict
Dictionnary of options passed to plt.rcParams.update. Only used if ax is None.
- matplotlib_style: str
Matplotlib style to be used. Only used if ax is None.
- Returns:
- figmatplotlib figure
The resulting figure with the distance vector obtained by d(S,X)
- plot(id_shapelet, ax=None, scatter_options={'alpha': 0.75, 'edgecolor': 'black', 'linewidths': 2, 's': 70, 'zorder': 3}, line_options={'alpha': 0.9, 'linestyle': '--', 'linewidth': 2}, figure_options={'dpi': 100, 'figsize': (10, 5)}, rc_Params_options={'font.size': 22}, matplotlib_style='seaborn-v0_8', custom_title_string=None)[source]¶
Plot the shapelet values.
- Parameters:
- id_shapeletint
ID of the shapelet to plot.
- axmatplotlib axe
A matplotlib axe on which to plot the figure. The default is None and will create a new figure of size figsize.
- scatter_optionsdict
Options to apply to scatter plot of the shapelet values.
- line_optionsdict
Dictionnary of options passed to plt.plot. Only used if ax is None.
- figure_optionsdict
Dictionnary of options passed to plt.figure. Only used if ax is None.
- rc_Params_options: dict
Dictionnary of options passed to plt.rcParams.update. Only used if ax is None.
- matplotlib_style: str
Matplotlib style to be used. Only used if ax is None.
- custom_title_stringstr
If not None, use this string as title for the plot instead of the default one based on the shapelet parametres.
- Returns:
- figmatplotlib figure
The resulting figure