The Mutual Information is a measure of the similarity between two labels
of the same data. Where ∣Ui∣ is the number of the samples
in cluster and is the number of the
samples in cluster , the Mutual Information
between clusterings and is given as:
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 U (i.e
label_true) with V (i.e. 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.
A clustering of the data into disjoint subsets, called U in
the above formula.
labels_pred : array-like of shape (n_samples,)
A clustering of the data into disjoint subsets, called V in
the above formula.
contingency : {array-like, sparse matrix} of shape (n_classes_true, n_classes_pred), default=None
A contingency matrix given by the
contingency_matrix function. If value
is None, it will be computed, otherwise the given value is used,
with labels_true and labels_pred ignored.
Returns:
mi : float
Mutual information, a non-negative value, measured in nats using the
natural logarithm.
Notes
The logarithm used is the natural logarithm (base-e).