rand_index#
- graph_tool.inference.rand_index(x, y, adjusted=False)[git][source]#
Returns the (adjusted) Rand index between two partitions.
- Parameters:
- xiterable of
intvalues orPropertyMap First partition.
- yiterable of
intvalues orPropertyMap Second partition.
- adjusted
bool(optional, default:False) If
True, the index adjusted for chance is returned.
- xiterable of
- Returns:
- RI
float (Adjusted) Rand index.
- RI
See also
split_join_distanceSplit-join distance between partitions
variation_informationVariation of information between partitions
reduced_mutual_informationReduced mutual information between partitions
partition_overlapMaximum overlap between partitions
Notes
The Rand index [rand-objective-1971] is the fraction of the \(\binom{N}{2}\) pairs of elements on which both partitions agree, i.e. that are placed together in both or apart in both,
\[RI(\boldsymbol x,\boldsymbol y) = 1 - \frac{\sum_r\binom{n_r}{2} + \sum_s\binom{n'_s}{2} - 2\sum_{rs}\binom{n_{rs}}{2}}{\binom{N}{2}},\]where \(n_{rs}\) is the number of elements in group \(r\) of \(\boldsymbol x\) and group \(s\) of \(\boldsymbol y\), and \(n_r\) and \(n'_s\) are the group sizes. The adjusted Rand index [hubert-comparing-1985] subtracts the value expected for random partitions with the same group sizes,
\[ARI(\boldsymbol x,\boldsymbol y) = \frac{\sum_{rs}\binom{n_{rs}}{2} - E} {\frac{1}{2}\left[\sum_r\binom{n_r}{2} + \sum_s\binom{n'_s}{2}\right] - E}, \quad E = \frac{\sum_r\binom{n_r}{2}\sum_s\binom{n'_s}{2}}{\binom{N}{2}},\]so that it is zero on average for unrelated partitions and one for identical partitions. Both indices are defined as one for \(N < 2\), and the adjusted index also when its denominator vanishes (e.g. when both partitions have a single group). The labels of the groups are irrelevant. This algorithm runs in time \(O(N)\).
References
[rand-objective-1971]William M. Rand, “Objective criteria for the evaluation of clustering methods”, Journal of the American Statistical Association 66, 846-850 (1971), DOI: 10.1080/01621459.1971.10482356 [sci-hub, @tor]
[hubert-comparing-1985]Lawrence Hubert and Phipps Arabie, “Comparing partitions”, Journal of Classification 2, 193-218 (1985), DOI: 10.1007/BF01908075 [sci-hub, @tor]
Examples
>>> x = np.random.randint(0, 10, 1000) >>> y = x.copy() >>> y[:200] = np.random.randint(0, 10, 200) >>> print(gt.rand_index(x, y), gt.rand_index(x, y, adjusted=True)) 0.936598598... 0.648086210...