code: def hclust_ordering(X, metric="sqeuclidean", anchor_first=False):
      """A leaf ordering is under-defined, this picks the ordering that keeps nearby samples similar."""
  
      # compute a hierarchical clustering and return the optimal leaf ordering
      D = scipy.spatial.distance.pdist(X, metric)
      cluster_matrix = scipy.cluster.hierarchy.complete(D)
      return scipy.cluster.hierarchy.leaves_list(
          scipy.cluster.hierarchy.optimal_leaf_ordering(
              cluster_matrix, D
          )
      )
  
file_path: shap/shap/utils/_clustering.py
imports: import warnings
  import numpy
  import pandas
  import scipy.cluster
  import scipy.spatial
  import sklearn
  from numba import njit
  from ._show_progress import show_progress
label_desc: Use image node_id 8 for calling a global function with example usage: hclust_ordering(X, metric, anchor_first) and returns: scipy