code: def get_distance(selection, contributions, mode, nb_features):
      """
      Determine how close we get to the output with all features by using only a subset of them
  
      Parameters
      ----------
      selection : list
          Indices of rows to be displayed on the stability plot
      contributions : DataFrame
          Calculated contribution values for the dataset
      mode : str
          "classification" or "regression"
      nb_features : int, optional
          Number of features used, by default 5
  
      Returns
      -------
      distance : array
          List of distances for each instance by using top selected features (ex: np.array([0.12, 0.16...])).
  
          * For regression:
  
              * normalized distance between the output of current model and output of full model
  
          * For classifciation:
  
              * distance between probability outputs (absolute value)
      """
      if mode == "classification" and len(contributions) == 2:
          contributions = contributions[1]
      assert nb_features <= contributions.shape[1]
  
      contributions = contributions.loc[selection].values
      top_features = np.array(
          [sorted(row, key=abs, reverse=True) for row in contributions]
      )[:, :nb_features]
      output_top_features = np.sum(top_features[:, :], axis=1)
      output_all_features = np.sum(contributions[:, :], axis=1)
  
      if mode == "regression":
          distance = abs(
              output_top_features - output_all_features
          ) / abs(output_all_features)
      elif mode == "classification":
          distance = abs(output_top_features - output_all_features)
      return distance
  
file_path: shapash/shapash/utils/explanation_metrics.py
imports: import numpy
  import pandas
  from sklearn.preprocessing import normalize
label_desc: Use image node_id 8 for calling a global function with example usage: get_distance(selection, contributions, mode, nb_features) and returns: distance