Interpret

Submodules

kale.interpret.model_weights module

kale.interpret.model_weights.select_top_weight(weights, select_ratio: float = 0.05)

Select top weights in magnitude, and the rest of weights will be zeros

Parameters
  • weights (array-like) – model weights, can be a vector or a higher order tensor

  • select_ratio (float, optional) – ratio of top weights to be selected. Defaults to 0.05.

Returns

top weights in the same shape with the input model weights

Return type

array-like

kale.interpret.visualize module

kale.interpret.visualize.plot_weights(weight_img, background_img=None, color_marker_pos='rs', color_marker_neg='gs', im_kwargs=None, marker_kwargs=None)

Visualize model weights

Parameters
  • weight_img (array-like) – Model weight/coefficients in 2D, could be a 2D slice of a 3D or higher order tensor.

  • background_img (array-like, optional) – 2D background image. Defaults to None.

  • color_marker_pos (str, optional) – Color and marker for weights in positive values. Defaults to red “rs”.

  • color_marker_neg (str, optional) – Color and marker for weights in negative values. Defaults to blue “gs”.

  • im_kwargs (dict, optional) – Keyword arguments for background images. Defaults to None.

  • marker_kwargs (dict, optional) – Keyword arguments for background images. Defaults to None.

Returns

Figure to plot.

Return type

[matplotlib.figure.Figure]

kale.interpret.visualize.plot_multi_images(images, n_cols=1, n_rows=None, marker_locs=None, image_titles=None, marker_titles=None, marker_cmap=None, figsize=None, im_kwargs=None, marker_kwargs=None, legend_kwargs=None, title_kwargs=None)

Plot multiple images with markers in one figure.

Parameters
  • images (array-like) – Images to plot, shape(n_samples, dim1, dim2)

  • n_cols (int, optional) – Number of columns for plotting multiple images. Defaults to 1.

  • n_rows (int, optional) – Number of rows for plotting multiple images. If None, n_rows = n_samples / n_cols.

  • marker_locs (array-like, optional) – Locations of markers, shape (n_samples, 2 * n_markers). Defaults to None.

  • marker_titles (list, optional) – Names of the markers, where len(marker_names) == n_markers. Defaults to None.

  • marker_cmap (str, optional) – Name of the color map used for plotting markers. Default to None.

  • image_titles (list, optional) – List of title for each image, where len(image_names) == n_samples. Defaults to None.

  • figsize (tuple, optional) – Figure size. Defaults to None.

  • im_kwargs (dict, optional) – Keyword arguments for plotting images. Defaults to None.

  • marker_kwargs (dict, optional) – Keyword arguments for markers. Defaults to None.

  • legend_kwargs (dict, optional) – Keyword arguments for legend. Defaults to None.

  • title_kwargs (dict, optional) – Keyword arguments for title. Defaults to None.

Returns

Figure to plot.

Return type

[matplotlib.figure.Figure]

kale.interpret.visualize.distplot_1d(data, labels=None, xlabel=None, ylabel=None, title=None, figsize=None, colors=None, title_kwargs=None, hist_kwargs=None)

Plot distribution of 1D data.

Parameters
  • data (array-like or list) – Data to plot.

  • labels (list, optional) – List of labels for each data. Defaults to None.

  • xlabel (str, optional) – Label for x-axis. Defaults to None.

  • ylabel (str, optional) – Label for y-axis. Defaults to None.

  • title (str, optional) – Title of the plot. Defaults to None.

  • figsize (tuple, optional) – Figure size. Defaults to None.

  • colors (str, optional) – Color of the line. Defaults to None.

  • title_kwargs (dict, optional) – Keyword arguments for title. Defaults to None.

  • hist_kwargs (dict, optional) – Keyword arguments for histogram. Defaults to None.

Returns

Figure to plot.

Return type

[matplotlib.figure.Figure]

Module contents