code: def _entropy(labels):
      
      if len(labels) == 0:
          return 1.0
      label_idx = np.unique(labels, return_inverse=True)[1]
      pi = np.bincount(label_idx).astype(np.float)
      pi = pi[pi > 0]
      pi_sum = np.sum(pi)
      # log(a / b) should be calculated as log(a) - log(b) for
      # possible loss of precision
      return -np.sum((pi / pi_sum) * (np.log(pi) - np.log(pi_sum)))
docs: Calculates the entropy for a labeling.
  
      Parameters
      ----------
      labels : list-like
          List of labels.
  
      Returns
      -------
      entropy : float
          Entropy of the labeling.
  
      .. note:: Based on sklearn.metrics.cluster.entropy