Module Expr Str ImportFrom alias ImportFrom alias ImportFrom alias Import alias identifier ImportFrom alias ImportFrom alias FunctionDef arguments args NameParam defaults body Return Call NameLoad NameLoad Num keyword Num decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareNotEq AttributeLoad NameLoad attr Num body Raise Call NameLoad BinOpMod Str TupleLoad AttributeLoad NameLoad attr If CompareNotEq AttributeLoad NameLoad attr Num body Raise Call NameLoad BinOpMod Str TupleLoad AttributeLoad NameLoad attr If CompareNotEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Raise Call NameLoad BinOpMod Str TupleLoad SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad Num body Expr Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num If CompareGt NameLoad NameLoad body Raise Call NameLoad Str If CompareGt NameLoad NameLoad body Raise Call NameLoad Str Assign NameStore Call AttributeLoad Call NameLoad TupleLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Index Num TupleLoad NameLoad NameLoad keyword TupleLoad NameLoad NameLoad keyword AttributeLoad NameLoad attr attr If CompareIsNot NameLoad NameLoad body Assign NameStore BinOpAdd NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If BoolOpOr CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Call NameLoad NameLoad body Return Num Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call NameLoad GeneratorExp Call NameLoad NameLoad comprehension NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call NameLoad GeneratorExp Call NameLoad NameLoad comprehension NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call NameLoad GeneratorExp Call NameLoad NameLoad comprehension NameStore Call AttributeLoad NameLoad attr Assign NameStore BinOpDiv BinOpMult NameLoad NameLoad Call NameLoad Call NameLoad NameLoad Num Assign NameStore BinOpDiv BinOpAdd NameLoad NameLoad Num Return BinOpDiv BinOpSub NameLoad NameLoad BinOpSub NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad If CompareEq Call NameLoad NameLoad Num body Return TupleLoad Num Num Num Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore IfExp NameLoad BinOpDiv NameLoad NameLoad Num Assign NameStore IfExp NameLoad BinOpDiv NameLoad NameLoad Num If CompareEq BinOpAdd NameLoad NameLoad Num body Assign NameStore Num orelse Assign NameStore BinOpDiv BinOpMult BinOpMult Num NameLoad NameLoad BinOpAdd NameLoad NameLoad Return TupleLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Return SubscriptLoad Call NameLoad NameLoad NameLoad NameLoad Index Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Return SubscriptLoad Call NameLoad NameLoad NameLoad NameLoad Index Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Return SubscriptLoad Call NameLoad NameLoad NameLoad NameLoad Index Num decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad Num body Expr Str If CompareIs NameLoad NameLoad body Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore CompareNotEq NameLoad Num Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad AugAssignDiv NameStore NameLoad Assign NameStore BinOpAdd BinOpAdd UnaryOpUSub Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index NameLoad Call NameLoad Call AttributeLoad NameLoad attr Call NameLoad Call AttributeLoad NameLoad attr Assign NameStore BinOpAdd BinOpMult NameLoad BinOpSub NameLoad Call NameLoad NameLoad BinOpMult NameLoad NameLoad Return Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If BoolOpOr CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num body Return Num Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Assign TupleStore NameStore NameStore TupleLoad Call NameLoad NameLoad Call NameLoad NameLoad Assign NameStore BinOpDiv BinOpSub NameLoad NameLoad BinOpSub Call NameLoad NameLoad NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Assign TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If BoolOpOr CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num CompareEqEq SubscriptLoad AttributeLoad NameLoad attr Index Num SubscriptLoad AttributeLoad NameLoad attr Index Num Num body Return Num Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str Assign NameStore Call NameLoad NameLoad NameLoad keyword NameLoad Assign TupleStore NameStore NameStore TupleLoad Call NameLoad NameLoad Call NameLoad NameLoad Assign NameStore BinOpDiv NameLoad Call NameLoad Call AttributeLoad NameLoad attr BinOpMult NameLoad NameLoad Num Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If CompareEq Call NameLoad NameLoad Num body Return Num Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Index Num Assign NameStore Call AttributeLoad Call NameLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore SubscriptLoad NameLoad Index CompareGt NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return UnaryOpUSub Call AttributeLoad NameLoad attr BinOpMult BinOpDiv NameLoad NameLoad BinOpSub Call AttributeLoad NameLoad attr NameLoad Call NameLoad NameLoad decorator_list
N/A N/A Utilities to evaluate the clustering performance of models

Functions named as *_score return a scalar value to maximize: the higher the
better.
 math log scipy.misc comb scipy.sparse coo_matrix N/A numpy np expected_mutual_info_fast expected_mutual_information utils.fixes bincount comb2 N/A N/A n N/A N/A N/A N/A comb n 2 exact 1 N/A check_clusterings N/A N/A labels_true labels_pred N/A N/A N/A Check that the two clusterings matching 1D integer arrays N/A labels_true N/A N/A np asarray labels_true N/A labels_pred N/A N/A np asarray labels_pred N/A N/A N/A labels_true ndim 1 N/A N/A N/A ValueError N/A labels_true must be 1D: shape is %r N/A N/A labels_true shape N/A N/A N/A labels_pred ndim 1 N/A N/A N/A ValueError N/A labels_pred must be 1D: shape is %r N/A N/A labels_pred shape N/A N/A N/A labels_true shape N/A labels_pred shape N/A N/A N/A ValueError N/A labels_true and labels_pred must have same size, got %d and %d N/A N/A N/A labels_true shape N/A 0 N/A N/A labels_pred shape N/A 0 N/A N/A labels_true labels_pred N/A contingency_matrix N/A N/A labels_true labels_pred eps max_n_classes N/A None 5000 N/A N/A Build a contingency matrix describing the relationship between labels.

    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

    eps: None or float
        If a float, that value is added to all values in the contingency
        matrix. This helps to stop NaN propagation.
        If ``None``, nothing is adjusted.

    max_n_classes : int, optional (default=5000)
        Maximal number of classeses handled for contingency_matrix.
        This help to avoid Memory error with regression target
        for mutual_information.

    Returns
    -------
    contingency: array, shape=[n_classes_true, n_classes_pred]
        Matrix :math:`C` such that :math:`C_{i, j}` is the number of samples in
        true class :math:`i` and in predicted class :math:`j`. If
        ``eps is None``, the dtype of this array will be integer. If ``eps`` is
        given, the dtype will be float.
     N/A N/A classes class_idx N/A N/A np unique labels_true return_inverse True N/A N/A clusters cluster_idx N/A N/A np unique labels_pred return_inverse True N/A n_classes N/A N/A classes shape N/A 0 N/A n_clusters N/A N/A clusters shape N/A 0 N/A N/A n_classes max_n_classes N/A N/A N/A ValueError Too many classes for a clustering metric. If you want to increase the limit, pass parameter max_n_classes to the scoring function N/A N/A n_clusters max_n_classes N/A N/A N/A ValueError Too many clusters for a clustering metric. If you want to increase the limit, pass parameter max_n_classes to the scoring function N/A contingency N/A N/A N/A coo_matrix N/A N/A N/A np ones N/A N/A class_idx shape N/A 0 N/A class_idx cluster_idx shape N/A n_classes n_clusters dtype N/A np int toarray N/A N/A eps None N/A N/A contingency N/A contingency eps N/A contingency N/A adjusted_rand_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A 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

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    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

     N/A N/A labels_true labels_pred N/A check_clusterings labels_true labels_pred N/A n_samples N/A N/A labels_true shape N/A 0 N/A classes N/A N/A np unique labels_true N/A clusters N/A N/A np unique labels_pred N/A N/A N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 1 N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 0 N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 N/A len labels_true N/A N/A 1.0 N/A contingency N/A contingency_matrix labels_true labels_pred max_n_classes max_n_classes N/A sum_comb_c N/A sum N/A N/A comb2 n_c N/A n_c N/A N/A contingency sum axis 1 N/A sum_comb_k N/A sum N/A N/A comb2 n_k N/A n_k N/A N/A contingency sum axis 0 N/A sum_comb N/A sum N/A N/A comb2 n_ij N/A n_ij N/A N/A contingency flatten N/A prod_comb N/A N/A sum_comb_c sum_comb_k N/A float N/A comb n_samples 2 N/A mean_comb N/A N/A sum_comb_k sum_comb_c 2.0 N/A N/A N/A sum_comb prod_comb N/A mean_comb prod_comb N/A homogeneity_completeness_v_measure N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A Compute the homogeneity and completeness and V-Measure scores at once

    Those metrics are based on normalized conditional entropy measures of
    the clustering labeling to evaluate given the knowledge of a Ground
    Truth class labels of the same samples.

    A clustering result satisfies homogeneity if all of its clusters
    contain only data points which are members of a single class.

    A clustering result satisfies completeness if all the data points
    that are members of a given class are elements of the same cluster.

    Both scores have positive values between 0.0 and 1.0, larger values
    being desirable.

    Those 3 metrics are independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score values in any way.

    V-Measure is furthermore symmetric: swapping ``labels_true`` and
    ``label_pred`` will give the same score. This does not hold for
    homogeneity and completeness.

    Read more in the :ref:`User Guide <homogeneity_completeness>`.

    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

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    homogeneity: float
       score between 0.0 and 1.0. 1.0 stands for perfectly homogeneous labeling

    completeness: float
       score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling

    v_measure: float
        harmonic mean of the first two

    See also
    --------
    homogeneity_score
    completeness_score
    v_measure_score
     N/A N/A labels_true labels_pred N/A check_clusterings labels_true labels_pred N/A N/A N/A len labels_true 0 N/A N/A N/A 1.0 1.0 1.0 N/A entropy_C N/A entropy labels_true N/A entropy_K N/A entropy labels_pred N/A MI N/A mutual_info_score labels_true labels_pred max_n_classes max_n_classes N/A homogeneity N/A entropy_C N/A MI entropy_C 1.0 N/A completeness N/A entropy_K N/A MI entropy_K 1.0 N/A N/A N/A homogeneity completeness 0.0 N/A N/A v_measure_score 0.0 N/A N/A v_measure_score N/A N/A N/A 2.0 homogeneity completeness N/A homogeneity completeness N/A N/A homogeneity completeness v_measure_score N/A homogeneity_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A Homogeneity metric of a cluster labeling given a ground truth

    A clustering result satisfies homogeneity if all of its clusters
    contain only data points which are members of a single class.

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is not symmetric: switching ``label_true`` with ``label_pred``
    will return the :func:`completeness_score` which will be different in
    general.

    Read more in the :ref:`User Guide <homogeneity_completeness>`.

    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

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    homogeneity: float
       score between 0.0 and 1.0. 1.0 stands for perfectly homogeneous labeling

    References
    ----------

    .. [1] `Andrew Rosenberg and Julia Hirschberg, 2007. V-Measure: A
       conditional entropy-based external cluster evaluation measure
       <http://aclweb.org/anthology/D/D07/D07-1043.pdf>`_

    See also
    --------
    completeness_score
    v_measure_score

    Examples
    --------

    Perfect labelings are homogeneous::

      >>> from sklearn.metrics.cluster import homogeneity_score
      >>> homogeneity_score([0, 0, 1, 1], [1, 1, 0, 0])
      1.0

    Non-perfect labelings that further split classes into more clusters can be
    perfectly homogeneous::

      >>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 0, 1, 2]))
      ...                                                  # doctest: +ELLIPSIS
      1.0...
      >>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 1, 2, 3]))
      ...                                                  # doctest: +ELLIPSIS
      1.0...

    Clusters that include samples from different classes do not make for an
    homogeneous labeling::

      >>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 1, 0, 1]))
      ...                                                  # doctest: +ELLIPSIS
      0.0...
      >>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 0, 0, 0]))
      ...                                                  # doctest: +ELLIPSIS
      0.0...

     N/A N/A N/A homogeneity_completeness_v_measure labels_true labels_pred max_n_classes N/A 0 N/A completeness_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A Completeness metric of a cluster labeling given a ground truth

    A clustering result satisfies completeness if all the data points
    that are members of a given class are elements of the same cluster.

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is not symmetric: switching ``label_true`` with ``label_pred``
    will return the :func:`homogeneity_score` which will be different in
    general.

    Read more in the :ref:`User Guide <homogeneity_completeness>`.

    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

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    completeness: float
       score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling

    References
    ----------

    .. [1] `Andrew Rosenberg and Julia Hirschberg, 2007. V-Measure: A
       conditional entropy-based external cluster evaluation measure
       <http://aclweb.org/anthology/D/D07/D07-1043.pdf>`_

    See also
    --------
    homogeneity_score
    v_measure_score

    Examples
    --------

    Perfect labelings are complete::

      >>> from sklearn.metrics.cluster import completeness_score
      >>> completeness_score([0, 0, 1, 1], [1, 1, 0, 0])
      1.0

    Non-perfect labelings that assign all classes members to the same clusters
    are still complete::

      >>> print(completeness_score([0, 0, 1, 1], [0, 0, 0, 0]))
      1.0
      >>> print(completeness_score([0, 1, 2, 3], [0, 0, 1, 1]))
      1.0

    If classes members are split across different clusters, the
    assignment cannot be complete::

      >>> print(completeness_score([0, 0, 1, 1], [0, 1, 0, 1]))
      0.0
      >>> print(completeness_score([0, 0, 0, 0], [0, 1, 2, 3]))
      0.0

     N/A N/A N/A homogeneity_completeness_v_measure labels_true labels_pred max_n_classes N/A 1 N/A v_measure_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A V-measure cluster labeling given a ground truth.

    This score is identical to :func:`normalized_mutual_info_score`.

    The V-measure is the harmonic mean between homogeneity and completeness::

        v = 2 * (homogeneity * completeness) / (homogeneity + completeness)

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is furthermore symmetric: switching ``label_true`` with
    ``label_pred`` will return the same score value. This can be useful to
    measure the agreement of two independent label assignments strategies
    on the same dataset when the real ground truth is not known.

    Read more in the :ref:`User Guide <homogeneity_completeness>`.

    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

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    v_measure: float
       score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling

    References
    ----------

    .. [1] `Andrew Rosenberg and Julia Hirschberg, 2007. V-Measure: A
       conditional entropy-based external cluster evaluation measure
       <http://aclweb.org/anthology/D/D07/D07-1043.pdf>`_

    See also
    --------
    homogeneity_score
    completeness_score

    Examples
    --------

    Perfect labelings are both homogeneous and complete, hence have score 1.0::

      >>> from sklearn.metrics.cluster import v_measure_score
      >>> v_measure_score([0, 0, 1, 1], [0, 0, 1, 1])
      1.0
      >>> v_measure_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 homogeneous, hence penalized::

      >>> print("%.6f" % v_measure_score([0, 0, 1, 2], [0, 0, 1, 1]))
      ...                                                  # doctest: +ELLIPSIS
      0.8...
      >>> print("%.6f" % v_measure_score([0, 1, 2, 3], [0, 0, 1, 1]))
      ...                                                  # doctest: +ELLIPSIS
      0.66...

    Labelings that have pure clusters with members coming from the same
    classes are homogeneous but un-necessary splits harms completeness
    and thus penalize V-measure as well::

      >>> print("%.6f" % v_measure_score([0, 0, 1, 1], [0, 0, 1, 2]))
      ...                                                  # doctest: +ELLIPSIS
      0.8...
      >>> print("%.6f" % v_measure_score([0, 0, 1, 1], [0, 1, 2, 3]))
      ...                                                  # doctest: +ELLIPSIS
      0.66...

    If classes members are completely split across different clusters,
    the assignment is totally incomplete, hence the V-Measure is null::

      >>> print("%.6f" % v_measure_score([0, 0, 0, 0], [0, 1, 2, 3]))
      ...                                                  # doctest: +ELLIPSIS
      0.0...

    Clusters that include samples from totally different classes totally
    destroy the homogeneity of the labeling, hence::

      >>> print("%.6f" % v_measure_score([0, 0, 1, 1], [0, 0, 0, 0]))
      ...                                                  # doctest: +ELLIPSIS
      0.0...

     N/A N/A N/A homogeneity_completeness_v_measure labels_true labels_pred max_n_classes N/A 2 N/A mutual_info_score N/A N/A labels_true labels_pred contingency max_n_classes N/A None 5000 N/A N/A Mutual Information between two clusterings

    The Mutual Information is a measure of the similarity between two labels of
    the same data. Where :math:`P(i)` is the probability of a random sample
    occurring in cluster :math:`U_i` and :math:`P'(j)` is the probability of a
    random sample occurring in cluster :math:`V_j`, the Mutual Information
    between clusterings :math:`U` and :math:`V` is given as:

    .. math::

        MI(U,V)=\sum_{i=1}^R \sum_{j=1}^C P(i,j)\log\frac{P(i,j)}{P(i)P'(j)}

    This is equal to the Kullback-Leibler divergence of the joint distribution
    with the product distribution of the marginals.

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is furthermore symmetric: switching ``label_true`` with
    ``label_pred`` will return the same score value. This can be useful to
    measure the agreement of two independent label assignments strategies
    on the same dataset when the real ground truth is not known.

    Read more in the :ref:`User Guide <mutual_info_score>`.

    Parameters
    ----------
    labels_true : int array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    labels_pred : array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    contingency: None or array, shape = [n_classes_true, n_classes_pred]
        A contingency matrix given by the :func:`contingency_matrix` function.
        If value is ``None``, it will be computed, otherwise the given value is
        used, with ``labels_true`` and ``labels_pred`` ignored.

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the mutual_info_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    mi: float
       Mutual information, a non-negative value

    See also
    --------
    adjusted_mutual_info_score: Adjusted against chance Mutual Information
    normalized_mutual_info_score: Normalized Mutual Information
     N/A N/A contingency None N/A N/A N/A labels_true labels_pred N/A check_clusterings labels_true labels_pred N/A contingency N/A contingency_matrix labels_true labels_pred max_n_classes max_n_classes N/A contingency N/A N/A np array contingency dtype float N/A contingency_sum N/A N/A np sum contingency N/A pi N/A N/A np sum contingency axis 1 N/A pj N/A N/A np sum contingency axis 0 N/A outer N/A N/A np outer pi pj N/A nnz N/A contingency 0.0 N/A contingency_nm N/A contingency N/A nnz N/A log_contingency_nm N/A N/A np log contingency_nm N/A contingency_nm contingency_sum N/A log_outer N/A N/A N/A N/A N/A np log N/A outer N/A nnz N/A log N/A N/A pi sum N/A log N/A N/A pj sum N/A mi N/A N/A contingency_nm N/A log_contingency_nm N/A log contingency_sum N/A contingency_nm log_outer N/A N/A N/A mi sum N/A adjusted_mutual_info_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A Adjusted Mutual Information between two clusterings

    Adjusted Mutual Information (AMI) is an adjustment of the Mutual
    Information (MI) score to account for chance. It accounts for the fact that
    the MI is generally higher for two clusterings with a larger number of
    clusters, regardless of whether there is actually more information shared.
    For two clusterings :math:`U` and :math:`V`, the AMI is given as::

        AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [max(H(U), H(V)) - E(MI(U, V))]

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is furthermore symmetric: switching ``label_true`` with
    ``label_pred`` will return the same score value. This can be useful to
    measure the agreement of two independent label assignments strategies
    on the same dataset when the real ground truth is not known.

    Be mindful that this function is an order of magnitude slower than other
    metrics, such as the Adjusted Rand Index.

    Read more in the :ref:`User Guide <mutual_info_score>`.

    Parameters
    ----------
    labels_true : int array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    labels_pred : array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    ami: float(upperlimited by 1.0)
       The AMI returns a value of 1 when the two partitions are identical
       (ie perfectly matched). Random partitions (independent labellings) have
       an expected AMI around 0 on average hence can be negative.

    See also
    --------
    adjusted_rand_score: Adjusted Rand Index
    mutual_information_score: Mutual Information (not adjusted for chance)

    Examples
    --------

    Perfect labelings are both homogeneous and complete, hence have
    score 1.0::

      >>> from sklearn.metrics.cluster import adjusted_mutual_info_score
      >>> adjusted_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])
      1.0
      >>> adjusted_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])
      1.0

    If classes members are completely split across different clusters,
    the assignment is totally in-complete, hence the AMI is null::

      >>> adjusted_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])
      0.0

    References
    ----------
    .. [1] `Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for
       Clusterings Comparison: Variants, Properties, Normalization and
       Correction for Chance, JMLR
       <http://jmlr.csail.mit.edu/papers/volume11/vinh10a/vinh10a.pdf>`_

    .. [2] `Wikipedia entry for the Adjusted Mutual Information
       <https://en.wikipedia.org/wiki/Adjusted_Mutual_Information>`_

     N/A N/A labels_true labels_pred N/A check_clusterings labels_true labels_pred N/A n_samples N/A N/A labels_true shape N/A 0 N/A classes N/A N/A np unique labels_true N/A clusters N/A N/A np unique labels_pred N/A N/A N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 1 N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 0 N/A N/A 1.0 N/A contingency N/A contingency_matrix labels_true labels_pred max_n_classes max_n_classes N/A contingency N/A N/A np array contingency dtype float N/A mi N/A mutual_info_score labels_true labels_pred contingency contingency N/A emi N/A expected_mutual_information contingency n_samples N/A N/A h_true h_pred N/A N/A entropy labels_true N/A entropy labels_pred N/A ami N/A N/A mi emi N/A N/A max h_true h_pred emi N/A ami N/A normalized_mutual_info_score N/A N/A labels_true labels_pred max_n_classes N/A 5000 N/A N/A Normalized Mutual Information between two clusterings

    Normalized Mutual Information (NMI) is an normalization of the Mutual
    Information (MI) score to scale the results between 0 (no mutual
    information) and 1 (perfect correlation). In this function, mutual
    information is normalized by ``sqrt(H(labels_true) * H(labels_pred))``

    This measure is not adjusted for chance. Therefore
    :func:`adjusted_mustual_info_score` might be preferred.

    This metric is independent of the absolute values of the labels:
    a permutation of the class or cluster label values won't change the
    score value in any way.

    This metric is furthermore symmetric: switching ``label_true`` with
    ``label_pred`` will return the same score value. This can be useful to
    measure the agreement of two independent label assignments strategies
    on the same dataset when the real ground truth is not known.

    Read more in the :ref:`User Guide <mutual_info_score>`.

    Parameters
    ----------
    labels_true : int array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    labels_pred : array, shape = [n_samples]
        A clustering of the data into disjoint subsets.

    max_n_classes: int, optional (default=5000)
        Maximal number of classes handled by the adjusted_rand_score
        metric. Setting it too high can lead to MemoryError or OS
        freeze

    Returns
    -------
    nmi: float
       score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling

    See also
    --------
    adjusted_rand_score: Adjusted Rand Index
    adjusted_mutual_info_score: Adjusted Mutual Information (adjusted
        against chance)

    Examples
    --------

    Perfect labelings are both homogeneous and complete, hence have
    score 1.0::

      >>> from sklearn.metrics.cluster import normalized_mutual_info_score
      >>> normalized_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])
      1.0
      >>> normalized_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])
      1.0

    If classes members are completely split across different clusters,
    the assignment is totally in-complete, hence the NMI is null::

      >>> normalized_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])
      0.0

     N/A N/A labels_true labels_pred N/A check_clusterings labels_true labels_pred N/A classes N/A N/A np unique labels_true N/A clusters N/A N/A np unique labels_pred N/A N/A N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 1 N/A N/A N/A classes shape N/A 0 N/A N/A clusters shape N/A 0 0 N/A N/A 1.0 N/A contingency N/A contingency_matrix labels_true labels_pred max_n_classes max_n_classes N/A contingency N/A N/A np array contingency dtype float N/A mi N/A mutual_info_score labels_true labels_pred contingency contingency N/A N/A h_true h_pred N/A N/A entropy labels_true N/A entropy labels_pred N/A nmi N/A mi N/A max N/A N/A np sqrt N/A h_true h_pred 1e-10 N/A nmi N/A entropy N/A N/A labels N/A N/A N/A Calculates the entropy for a labeling. N/A N/A N/A len labels 0 N/A N/A 1.0 N/A label_idx N/A N/A N/A np unique labels return_inverse True N/A 1 N/A pi N/A N/A N/A bincount label_idx astype N/A np float N/A pi N/A pi N/A N/A pi 0 N/A pi_sum N/A N/A np sum pi N/A N/A N/A N/A np sum N/A N/A pi pi_sum N/A N/A N/A np log pi N/A log pi_sum N/A