induwara.lk
induwara.lkAI · Clustering evaluation

Fowlkes-Mallows Index Calculator

Paste your ground-truth labels and a clustering's predicted labels — or the raw pair counts — and get the Fowlkes-Mallows Index, the pairwise precision and recall, and the full pair-confusion working. Matches scikit-learn. Free, no signup, runs in your browser.

By Induwara AshinsanaUpdated Jul 13, 2026
Fowlkes–Mallows Index
One label per item — commas, spaces or new lines.6 items
Must match the item count of the true labels.6 items
Examples
Fowlkes–Mallows Index
Weak
0.4714

Weak agreement — many co-clustered pairs are missed or spurious.

Pairwise precision
0.6667
TP / (TP + FP) — share of predicted-together pairs that truly belong together.
Pairwise recall
0.3333
TP / (TP + FN) — share of truly-together pairs the clustering recovered.

Working

FMI = TP / √((TP + FP)(TP + FN))

= 2 / √((2 + 1)(2 + 4))

= 2 / √(3 · 6) = 0.4714

= √(precision · recall) = √(0.6667 · 0.3333)

Pair-confusion counts

TPTogether in both true and predicted2
FPTogether in predicted only1
FNTogether in true only4
TNSeparated in both8
Total pairs C(6, 2)15

Contingency table

True \ Pred012Row Σ
02103
10123
Col Σ2226

Rows = true clusters, columns = predicted clusters. Grand total n = 6 items.

Computed entirely in your browser — nothing is uploaded. Formula per scikit-learn and Fowlkes & Mallows (1983); last verified 2026-07-13.

How it works

The Fowlkes-Mallows Index (FMI) measures how well a predicted clustering reproduces a known reference grouping of the same items — for example the clusters a k-means run produced versus the true class labels. It is an external metric: it needs ground truth, unlike the Silhouette, Davies-Bouldin or Calinski-Harabasz scores, which judge a clustering from the feature vectors alone. FMI works at the level of pairs of items.

Consider all C(n,2) = n(n−1)/2 unordered item pairs. Each pair is classified by whether the two items share a cluster in the true labeling and in the predicted labeling (Fowlkes & Mallows 1983; scikit-learn User Guide §2.3.11):

  • TP — same cluster in both true and predicted.
  • FP — same predicted cluster, different true cluster.
  • FN — same true cluster, different predicted cluster.
  • TN — different cluster in both.

The index is the number of true positives divided by the geometric mean of the two “together” totals:

  • precision P = TP / (TP + FP)
  • recall R = TP / (TP + FN)
  • FMI = TP / √((TP + FP)(TP + FN)) = √(P · R)

So FMI is the geometric mean of pairwise precision and recall. It ranges over [0, 1]: 1 means the two clusterings are identical up to relabeling, and a value near what independent labelings would score means no meaningful agreement. Because the comparison only depends on which items share a cluster, it is permutation-invariant — renaming clusters changes nothing. In practice the tool builds a contingency table where n_ij is the count of items in true cluster i and predicted cluster j, then uses the closed-form TP = Σ C(n_ij, 2) with the row-sum and column-sum totals to get FP and FN — so it stays fast even for large inputs.

One edge case: if TP + FP = 0 or TP + FN = 0 (a degenerate clustering with no co-clustered pairs), the formula would divide by zero, so scikit-learn returns 0.0 and this tool mirrors that and flags it. All pair counts stay exact integers, so results match scikit-learn to full double precision, and in label mode every FMI is independently re-derived from a distinct sum-of-squares formula before it is shown.

Worked examples

Example 1 — partial agreement (scikit-learn doc case), n = 6

  1. true = [0,0,0,1,1,1], pred = [0,0,1,1,2,2]; contingency rows [2,1,0] and [0,1,2].
  2. TP = C(2,2)+C(1,2)+C(1,2)+C(2,2) = 1+0+0+1 = 2
  3. sumTrue = C(3,2)+C(3,2) = 6; sumPred = C(2,2)·3 = 3
  4. FP = 3 − 2 = 1; FN = 6 − 2 = 4; TN = 15 − 2 − 1 − 4 = 8
  5. P = 2/3 = 0.6667; R = 2/6 = 0.3333
  6. FMI = 2/√(3·6) = 2/√18 = 0.4714 (sklearn: 0.47140452…)

Example 2 — identical partitions under relabeling, n = 4

  1. true = [0,0,1,1], pred = [1,1,0,0] — same grouping, different cluster names.
  2. TP = C(2,2)+C(2,2) = 2; sumTrue = 2; sumPred = 2; FP = 0; FN = 0
  3. FMI = 2/√(2·2) = 2/2 = 1.0 → Near-identical
  4. Precision = recall = 1.0 — relabeling does not affect the score.

Example 3 — larger partial agreement, n = 8

  1. true = [0,0,0,0,1,1,1,1], pred = [0,0,0,1,1,1,2,2].
  2. sumTrue = C(4,2)+C(4,2) = 12; sumPred = C(3,2)+C(3,2)+C(2,2) = 7
  3. TP: pred-0 {0,1,2} all true-0 → 3; pred-1 {3,4,5}: only (4,5) share true → 1; pred-2 {6,7} → 1. TP = 5
  4. FP = 7 − 5 = 2; FN = 12 − 5 = 7; P = 5/7 = 0.7143; R = 5/12 = 0.4167
  5. FMI = 5/√(7·12) = 5/√84 = 0.5455 = √(0.7143 · 0.4167)

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, an edge case, or want another clustering metric added next?

Email me at [email protected] — most fixes ship within 24 hours.