I wanted to find the normalized mutual information to validate a clustering algorithm, but I've encountered two different values depending on the library I use.

In Python:

from sklearn import metrics
labels_true = [0, 0, 0, 1, 1, 1]
labels_pred = [1, 1, 0, 0, 3, 3]

nmi = metrics.normalized_mutual_info_score(labels_true, labels_pred)

This returns nmi = 0.52954.

In R:

labels_true = c(0, 0, 0, 1, 1, 1)
labels_pred = c(1, 1, 0, 0, 3, 3)

nmi = NMI(labels_true,labels_pred)

This returns n = 0.42061.

Which one should I trust? I don't really know why they are returning different results if there is a closed formula for NMI...


It turns out that the R version uses by default the 'max' variant of the NMI, while Python's uses 'sqrt'.

Doing this in R will yield the same results:

NMI(labels_true, labels_pred, variant="sqrt")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.