fuzzyclust.validity.fuzzy_rand_index#
- fuzzyclust.validity.fuzzy_rand_index(U1, U2, method='huellermeier', tnorm=None)[source]#
Fuzzy Rand index between two fuzzy partitions of the same samples.
The Rand index counts the pairs of samples on which two partitions agree—together in both or apart in both—over all pairs. Two fuzzy generalizations are implemented.
"huellermeier"(Hüllermeier, Rifqi, Henzgen & Senge, 2012): every partition defines a fuzzy equivalence relation \(E_U(k,l)=1-\tfrac12\sum_i|\mu_{ik}-\mu_{il}|\) (the degree to which samples \(k\) and \(l\) are in the same cluster), and the index is one minus the normalized distance between the two relations,\[R_E(\mathbf{U}_1,\mathbf{U}_2)=1-\frac{\sum_{k<l}|E_1(k,l)-E_2(k,l)|}{N(N-1)/2} .\]This distance-based form is the definition of the paper and is what
tnorm=Nonecomputes. Passing a t-norm instead evaluates the count-based form \((a+d)/(a+b+c+d)\) with \(a=\sum\top(E_1,E_2)\), \(b=\sum\top(E_1,1-E_2)\), etc.; for soft partitions the two forms differ (the four degrees of a pair need not sum to one), for hard partitions both equal the classical Rand index. The adjusted Rand and Jaccard variants use the counts (Łukasiewicz t-norm by default)."campello"(Campello, 2007): for every pair the degrees of being in the same cluster, \(V_{kl}=\sum_i\top(\mu_{ik},\mu_{il})\), and in different clusters, \(X_{kl}=\sum_{i\neq j}\top(\mu_{ik},\mu_{jl})\), are formed with a t-norm \(\top\) for both partitions, and the four counts are \(a=\sum_{k<l}\top(V^{(1)}_{kl},V^{(2)}_{kl})\), \(b=\sum\top(V^{(1)},X^{(2)})\), \(c=\sum\top(X^{(1)},V^{(2)})\), \(d=\sum\top(X^{(1)},X^{(2)})\); the Rand index is \((a+d)/(a+b+c+d)\).
Both reduce to the classical Rand index for hard partitions.
- Parameters:
- U1, U2array_like
ofshape(n_samples,n_clusters_1)and(n_samples,n_clusters_2) Membership matrices (rows sum to one); hard partitions as one-hot matrices (
fuzzyclust._utils.labels_to_membership()).- method{“huellermeier”, “campello”}, default=”huellermeier”
- tnorm{“product”, “minimum”, “lukasiewicz”}
orNone, default=None t-norm;
Nonegives the distance-based index for"huellermeier"and the product t-norm for"campello".
- U1, U2array_like
- Returns:
floatin[0, 1]
References
[1]E. Hüllermeier, M. Rifqi, S. Henzgen, R. Senge, “Comparing fuzzy partitions: a generalization of the Rand index and related measures”, IEEE Trans. Fuzzy Systems 20(3), 546–556, 2012.
[2]R. J. G. B. Campello, “A fuzzy extension of the Rand index and other related indexes for clustering and classification assessment”, Pattern Recognition Letters 28(7), 833–841, 2007.
Examples
>>> from fuzzyclust.cluster import FCM, GK >>> from fuzzyclust.datasets import make_fuzzy_blobs >>> from fuzzyclust.validity import fuzzy_rand_index >>> X, _ = make_fuzzy_blobs(random_state=0) >>> U1 = FCM(n_clusters=3, random_state=0).fit(X).membership_ >>> U2 = GK(n_clusters=3, random_state=0).fit(X).membership_ >>> round(fuzzy_rand_index(U1, U2), 2) > 0.9 True
Examples using fuzzyclust.validity.fuzzy_rand_index#
Three routes to the number of clusters: merging, validity scan, and stability
Collaborative fuzzy clustering across three data sites