code: def compute_prototype_importances(
      summary: "Explanation",
      trainset: Tuple[np.ndarray, np.ndarray],
      preprocess_fn: Optional[
          Callable[[np.ndarray], np.ndarray]
      ] = None,
      knn_kw: Optional[dict] = None,
  ) -> Dict[str, Optional[np.ndarray]]:
      """
      Computes the importance of each prototype. The importance of a prototype is the number of assigned
      training instances correctly classified according to the 1-KNN classifier
      (Bien and Tibshirani (2012): https://arxiv.org/abs/1202.5933).
  
      Parameters
      ----------
      summary
          An `Explanation` object produced by a call to the
          :py:meth:`alibi.prototypes.protoselect.ProtoSelect.summarise` method.
      trainset
          Tuple, `(X_train, y_train)`, consisting of the training data instances with the corresponding labels.
      preprocess_fn
          Optional preprocessor function. If ``preprocess_fn=None``, no preprocessing is applied.
      knn_kw
          Keyword arguments passed to `sklearn.neighbors.KNeighborsClassifier`. The `n_neighbors` will be
          set automatically to 1, but the `metric` has to be specified according to the kernel distance used.
          If the `metric` is not specified, it will be set by default to ``'euclidean'``.
          See parameters description:
          https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html
  
      Returns
      -------
      A dictionary containing:
  
       - ``'prototype_indices'`` - an array of the prototype indices.
  
       - ``'prototype_importances'`` - an array of prototype importances.
  
       - ``'X_protos'`` - an array of raw prototypes.
  
       - ``'X_protos_ft'`` - an optional array of preprocessed prototypes. If the ``preprocess_fn=None``, \
       no preprocessing is applied and ``None`` is returned instead.
      """
      if knn_kw is None:
          knn_kw = {}
  
      if knn_kw.get("metric") is None:
          knn_kw.update({"metric": "euclidean"})
          logger.warning(
              "KNN metric was not specified. Automatically setting `metric='euclidean'`."
          )
  
      X_train, y_train = trainset
      X_protos = summary.data["prototypes"]
      y_protos = summary.data["prototype_labels"]
  
      # preprocess the dataset
      X_train_ft = (
          _batch_preprocessing(X=X_train, preprocess_fn=preprocess_fn)
          if (preprocess_fn is not None)
          else X_train
      )
      X_protos_ft = (
          _batch_preprocessing(X=X_protos, preprocess_fn=preprocess_fn)
          if (preprocess_fn is not None)
          else X_protos
      )
  
      # train knn classifier
      knn = KNeighborsClassifier(n_neighbors=1, **knn_kw)
      knn = knn.fit(X=X_protos_ft, y=y_protos)
  
      # get neighbors indices for each training instance
      neigh_idx = knn.kneighbors(
          X=X_train_ft, n_neighbors=1, return_distance=False
      ).reshape(-1)
  
      # compute how many correct labeled instances each prototype covers
      idx, counts = np.unique(
          neigh_idx[y_protos[neigh_idx] == y_train], return_counts=True
      )
      return {
          "prototype_indices": idx,
          "prototype_importances": counts,
          "X_protos": X_protos[idx],
          "X_protos_ft": None
          if (preprocess_fn is None)
          else X_protos_ft[idx],
      }
  
imports: import logging
  from copy import deepcopy
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from matplotlib.offsetbox import AnnotationBbox, OffsetImage
  from skimage.transform import resize
  from sklearn.model_selection import KFold
  from sklearn.neighbors import KNeighborsClassifier
  from tqdm import tqdm
  from alibi.api.defaults import DEFAULT_DATA_PROTOSELECT, DEFAULT_META_PROTOSELECT
  from alibi.api.interfaces import Explanation, FitMixin, Summariser
  from alibi.utils.distance import batch_compute_kernel_matrix
  from alibi.utils.kernel import EuclideanDistance
label_desc: Use image node_id 6 for calling a global function with example usage: compute_prototype_importances(summary, trainset, preprocess_fn, knn_kw) and returns: dict