Skip to content

Instantly share code, notes, and snippets.

@jayelm
Last active May 16, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayelm/9a024359b15516a3d530023ad9ab413d to your computer and use it in GitHub Desktop.
Save jayelm/9a024359b15516a3d530023ad9ab413d to your computer and use it in GitHub Desktop.
V-Measure (Rosenberg, 2007) Implementation in R. This almost exactly follows scikit-learn's implementation (http://scikit-learn.org/stable/modules/generated/sklearn.metrics.homogeneity_completeness_v_measure.html)
library(infotheo)
v.measure <- function(a, b) {
mi <- mutinformation(a, b)
entropy.a <- entropy(a)
entropy.b <- entropy(b)
if (entropy.a == 0.0) {
homogeneity <- 1.0
} else {
homogeneity <- mi / entropy.a
}
if (entropy.b == 0.0) {
completeness <- 1.0
} else {
completeness <- mi / entropy.b
}
if (homogeneity + completeness == 0.0) {
v.measure.score <- 0.0
} else {
v.measure.score <- (2.0 * homogeneity * completeness
/ (homogeneity + completeness))
}
# Can also return homogeneity and completeness if wanted
v.measure.score
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment