code: def adjusted_rand_score(labels_true, labels_pred):
      """Rand index adjusted for chance.
  
      The Rand Index computes a similarity measure between two clusterings
      by considering all pairs of samples and counting pairs that are
      assigned in the same or different clusters in the predicted and
      true clusterings.
  
      The raw RI score is then "adjusted for chance" into the ARI score
      using the following scheme::
  
          ARI = (RI - Expected_RI) / (max(RI) - Expected_RI)
  
      The adjusted Rand index is thus ensured to have a value close to
      0.0 for random labeling independently of the number of clusters and
      samples and exactly 1.0 when the clusterings are identical (up to
      a permutation).
  
      ARI is a symmetric measure::
  
          adjusted_rand_score(a, b) == adjusted_rand_score(b, a)
  
      Read more in the :ref:`User Guide <adjusted_rand_score>`.
  
      Parameters
      ----------
      labels_true : int array, shape = [n_samples]
          Ground truth class labels to be used as a reference
  
      labels_pred : array, shape = [n_samples]
          Cluster labels to evaluate
  
      Returns
      -------
      ari : float
         Similarity score between -1.0 and 1.0. Random labelings have an ARI
         close to 0.0. 1.0 stands for perfect match.
  
      Examples
      --------
  
      Perfectly maching labelings have a score of 1 even
  
        >>> from sklearn.metrics.cluster import adjusted_rand_score
        >>> adjusted_rand_score([0, 0, 1, 1], [0, 0, 1, 1])
        1.0
        >>> adjusted_rand_score([0, 0, 1, 1], [1, 1, 0, 0])
        1.0
  
      Labelings that assign all classes members to the same clusters
      are complete be not always pure, hence penalized::
  
        >>> adjusted_rand_score([0, 0, 1, 2], [0, 0, 1, 1])  # doctest: +ELLIPSIS
        0.57...
  
      ARI is symmetric, so labelings that have pure clusters with members
      coming from the same classes but unnecessary splits are penalized::
  
        >>> adjusted_rand_score([0, 0, 1, 1], [0, 0, 1, 2])  # doctest: +ELLIPSIS
        0.57...
  
      If classes members are completely split across different clusters, the
      assignment is totally incomplete, hence the ARI is very low::
  
        >>> adjusted_rand_score([0, 0, 0, 0], [0, 1, 2, 3])
        0.0
  
      References
      ----------
  
      .. [Hubert1985] `L. Hubert and P. Arabie, Comparing Partitions,
        Journal of Classification 1985`
        http://link.springer.com/article/10.1007%2FBF01908075
  
      .. [wk] https://en.wikipedia.org/wiki/Rand_index#Adjusted_Rand_index
  
      See also
      --------
      adjusted_mutual_info_score: Adjusted Mutual Information
  
      """
      labels_true, labels_pred = check_clusterings(
          labels_true, labels_pred
      )
      n_samples = labels_true.shape[0]
      n_classes = np.unique(labels_true).shape[0]
      n_clusters = np.unique(labels_pred).shape[0]
  
      # Special limit cases: no clustering since the data is not split;
      # or trivial clustering where each document is assigned a unique cluster.
      # These are perfect matches hence return 1.0.
      if (
          n_classes == n_clusters == 1
          or n_classes == n_clusters == 0
          or n_classes == n_clusters == n_samples
      ):
          return 1.0
  
      # Compute the ARI using the contingency data
      contingency = contingency_matrix(
          labels_true, labels_pred, sparse=True
      )
      sum_comb_c = sum(
          comb2(n_c) for n_c in np.ravel(contingency.sum(axis=1))
      )
      sum_comb_k = sum(
          comb2(n_k) for n_k in np.ravel(contingency.sum(axis=0))
      )
      sum_comb = sum(comb2(n_ij) for n_ij in contingency.data)
  
      prod_comb = (sum_comb_c * sum_comb_k) / comb(n_samples, 2)
      mean_comb = (sum_comb_k + sum_comb_c) / 2.0
      return (sum_comb - prod_comb) / (mean_comb - prod_comb)
  
imports: from __future__ import division
  from math import log
  import numpy
  from scipy.misc import comb
  from scipy import sparse
  from .expected_mutual_info_fast import expected_mutual_information
  from ...utils.fixes import bincount
  from ...utils.validation import check_array
label_desc: Use image node_id 4 for calling a global function with example usage: adjusted_rand_score(labels_true, labels_pred) and returns: unknown, int