docstr: Summarises the background data to `n_background_samples` in order to reduce the computational cost. If the
  background data is a `shap_utils.Data object`, no summarisation is performed.
  
  Returns
  -------
  If the user has specified grouping, then the input object is subsampled and an object of the same         type is returned. Otherwise, a `shap_utils.Data` object containing the result of a k-means algorithm         is wrapped in a `shap_utils.DenseData` object and returned. The samples are weighted according to the         frequency of the occurrence of the clusters in the original data.
code: def _summarise_background(
      self,
      background_data: Union[
          shap_utils.Data, pd.DataFrame, np.ndarray, sparse.spmatrix
      ],
      n_background_samples: int,
  ) -> Union[
      shap_utils.Data, pd.DataFrame, np.ndarray, sparse.spmatrix
  ]:
      """
          Summarises the background data to `n_background_samples` in order to reduce the computational cost. If the
          background data is a `shap_utils.Data object`, no summarisation is performed.
  
          Returns
          -------
          If the user has specified grouping, then the input object is subsampled and an object of the same \
          type is returned. Otherwise, a `shap_utils.Data` object containing the result of a k-means algorithm \
          is wrapped in a `shap_utils.DenseData` object and returned. The samples are weighted according to the \
          frequency of the occurrence of the clusters in the original data.
          """
  
      if isinstance(background_data, shap_utils.Data):
          msg = (
              "Received option to summarise the data but the background_data object "
              "was an instance of shap_utils.Data. No summarisation will take place!"
          )
          logger.warning(msg)
          return background_data
  
      if background_data.ndim == 1:
          msg = (
              "Received option to summarise the data but the background_data object only had "
              "one record with {} features. No summarisation will take place!"
          )
          logger.warning(msg.format(len(background_data)))
          return background_data
  
      self.summarise_background = True
  
      # if the input is sparse, we assume there are categorical variables and use random sampling, not kmeans
      if (
          self.use_groups
          or self.categorical_names
          or isinstance(background_data, sparse.spmatrix)
      ):
          return shap.sample(
              background_data, nsamples=n_background_samples
          )
      else:
          logger.info(
              "When summarising with kmeans, the samples are weighted in proportion to their "
              "cluster occurrence frequency. Please specify a different weighting of the samples "
              "through the by passing a weights of len=n_background_samples to the constructor!"
          )
          return shap.kmeans(background_data, n_background_samples)
  
imports: import copy
  import logging
  from functools import partial
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import numpy
  import pandas
  import shap
  import shap.utils._legacy
  from scipy import sparse
  from scipy.special import expit
  from shap import KernelExplainer
  from alibi.api.defaults import DEFAULT_DATA_KERNEL_SHAP, DEFAULT_DATA_TREE_SHAP, DEFAULT_META_KERNEL_SHAP, DEFAULT_META_TREE_SHAP
  from alibi.api.interfaces import Explainer, Explanation, FitMixin
  from alibi.utils.wrappers import methdispatch
label_desc: Use image node_id 3 for calling the KernelShap obj's underlying member method code with example usage: obj._summarise_background(background_data, n_background_samples) and returns: background_data, background_data, shap, shap