Title: | Clustering and Link Prediction Evaluation in R |
---|---|
Description: | Tools for evaluating link prediction and clustering algorithms with respect to ground truth. Includes efficient implementations of common performance measures such as pairwise precision/recall, cluster homogeneity/completeness, variation of information, Rand index etc. |
Authors: | Neil Marchant [aut, cre], Rebecca Steorts [aut], Olivier Binette [ctb] |
Maintainer: | Neil Marchant <[email protected]> |
License: | GPL-2 |
Version: | 0.1.2 |
Built: | 2024-11-06 04:41:36 UTC |
Source: | https://github.com/cleanzr/clevr |
Computes the accuracy of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
accuracy_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
accuracy_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
num_pairs |
the total number of coreferent and non-coreferent pairs, excluding equivalent pairs with reversed ids. |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The accuracy is defined as:
where:
is the set of true coreferent pairs,
is the set of predicted coreferent pairs,
is the set of true non-coreferent pairs,
is the set of predicted non-coreferent pairs, and
is the total number of coreferent and non-coreferent pairs.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements accuracy_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements accuracy_pairs(true_pairs, pred_pairs, num_pairs)
Computes the adjusted Rand index (ARI) between two clusterings, such as a predicted and ground truth clustering.
adj_rand_index(true, pred)
adj_rand_index(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
The adjusted Rand index (ARI) is a variant of the Rand index (RI) which is corrected for chance using the Permutation Model for clusterings. It is related to the RI as follows:
where is the expected value of the RI under the Permutation
Model.
Unlike the RI, the ARI takes values in the range -1 to 1. A value
of 1 indicates that the clusterings are identical, while a value of
0 indicates the clusterings are drawn randomly independent of one
another.
Hubert, L., Arabie, P. "Comparing partitions." Journal of Classification 2, 193–218 (1985). doi:10.1007/BF01908075
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering adj_rand_index(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering adj_rand_index(true, pred)
Computes the balanced accuracy of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
balanced_accuracy_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
balanced_accuracy_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
num_pairs |
the total number of coreferent and non-coreferent pairs, excluding equivalent pairs with reversed ids. |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The balanced accuracy is defined as:
where:
is the set of true coreferent pairs,
is the set of predicted coreferent pairs,
is the set of true non-coreferent pairs, and
is the set of predicted non-coreferent pairs.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements balanced_accuracy_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements balanced_accuracy_pairs(true_pairs, pred_pairs, num_pairs)
Coerce a collection of element pairs into canonical form. Facilitates testing of equivalence.
canonicalize_pairs(pairs, ordered = FALSE)
canonicalize_pairs(pairs, ordered = FALSE)
pairs |
a matrix or data.frame of element pairs where rows correspond to element pairs and columns correspond to element identifiers. |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
Returns the element pairs in canonical form, so that:
the first element id precedes the second element id lexicographically
if ordered = FALSE
—i.e. pair (3, 2) becomes pair (2, 3);
pairs with missing element ids are removed;
duplicate pairs are removed; and
the rows in the matrix/data.frame pairs are sorted lexicographically by the first element id, then by the second element id.
messy_pairs <- rbind(c(2,1), c(1,2), c(3,1), c(1,2)) clean_pairs <- canonicalize_pairs(messy_pairs) all(rbind(c(1,2), c(1,3)) == clean_pairs) # duplicates removed and order fixed
messy_pairs <- rbind(c(2,1), c(1,2), c(3,1), c(1,2)) clean_pairs <- canonicalize_pairs(messy_pairs) all(rbind(c(1,2), c(1,3)) == clean_pairs) # duplicates removed and order fixed
Transform between different representations of a clustering.
clusters_to_membership(clusters, elem_ids = NULL, clust_ids = NULL) membership_to_clusters(membership, elem_ids = NULL, clust_ids = NULL) clusters_to_pairs(clusters) membership_to_pairs(membership, elem_ids = NULL) pairs_to_membership(pairs, elem_ids) pairs_to_clusters(pairs, elem_ids)
clusters_to_membership(clusters, elem_ids = NULL, clust_ids = NULL) membership_to_clusters(membership, elem_ids = NULL, clust_ids = NULL) clusters_to_pairs(clusters) membership_to_pairs(membership, elem_ids = NULL) pairs_to_membership(pairs, elem_ids) pairs_to_clusters(pairs, elem_ids)
clusters |
a representation of a clustering as a list of vectors,
where the i-th vector contains the identifiers of elements assigned to the
i-th cluster. If |
elem_ids |
a vector specifying the complete set of identifiers for the
cluster elements in canonical order. Optional for all functions excluding
|
clust_ids |
a vector specifying the complete set of identifiers for the clusters in canonical order. Optional for all functions. |
membership |
a representation of a clustering as a membership vector,
where the i-th entry contains the cluster identifier for the i-th element.
If |
pairs |
a representation of a clustering as a matrix or data.frame
containing all pairs of elements that are co-clustered. The rows index
of the matrix/data.frame index pairs and columns index the identifiers
of the constituent elements. The |
clusters_to_membership
and pairs_to_membership
both return a
membership vector representation of the clustering. The order of the
elements is taken from elem_ids
if specified, otherwise the elements are
ordered lexicographically by their identifiers. For
pairs_to_membership
, the cluster identifiers cannot be recovered and
are taken to be integers.
membership_to_clusters
and pairs_to_clusters
both return a
representation of the clustering as a list of vectors. The order of the
clusters is taken from clust_ids
if specified, otherwise the clusters
are ordered lexicographically by their identifiers. For
pairs_to_clusters
, the cluster identifiers cannot be recovered and
are taken to be integers.
clusters_to_pairs
and membership_to_pairs
both return a
representation of the clustering as a matrix of element pairs that are
co-clustered. This representation results in loss of information, as
singleton clusters (with one element) and cluster identifiers are not
represented.
## A clustering of three items represented as a membership vector m <- c("Item1" = 1, "Item2" = 2, "Item3" = 1) # Transform to list of clusters membership_to_clusters(m) # Specify different identifiers for the items membership_to_clusters(m, elem_ids = c(1, 2, 3)) # Transform to array of pairs that are co-clustered membership_to_pairs(m) ## A clustering represented as a list of clusters cl <- list("ClustA" = c(1,3), "ClustB" = c(2)) # Transform to membership vector representation clusters_to_membership(cl) # Transform to array of pairs that are co-clustered clusters_to_pairs(cl) ## A clustering (incompletely) represented as an array of pairs that ## are co-clustered p <- rbind(c(1,3)) # pairs of elements in the same cluster ids <- c(1,2,3) # necessary to specify set of all elements # Transform to membership vector representation pairs_to_membership(p, ids) # Transform to list of clusters pairs_to_clusters(p, ids)
## A clustering of three items represented as a membership vector m <- c("Item1" = 1, "Item2" = 2, "Item3" = 1) # Transform to list of clusters membership_to_clusters(m) # Specify different identifiers for the items membership_to_clusters(m, elem_ids = c(1, 2, 3)) # Transform to array of pairs that are co-clustered membership_to_pairs(m) ## A clustering represented as a list of clusters cl <- list("ClustA" = c(1,3), "ClustB" = c(2)) # Transform to membership vector representation clusters_to_membership(cl) # Transform to array of pairs that are co-clustered clusters_to_pairs(cl) ## A clustering (incompletely) represented as an array of pairs that ## are co-clustered p <- rbind(c(1,3)) # pairs of elements in the same cluster ids <- c(1,2,3) # necessary to specify set of all elements # Transform to membership vector representation pairs_to_membership(p, ids) # Transform to list of clusters pairs_to_clusters(p, ids)
Computes the completeness between two clusterings, such as a predicted and ground truth clustering.
completeness(true, pred)
completeness(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
Completeness is an entropy-based measure of the similarity
between two clusterings, say and
. The completeness
is high if all members of a given cluster in
are assigned
to a single cluster in
. The completeness ranges between 0
and 1, where 1 indicates perfect completeness.
Rosenberg, A. and Hirschberg, J. "V-measure: A conditional entropy-based external cluster evaluation measure." Proceedings of the 2007 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning (EMNLP-CoNLL), (2007).
homogeneity
evaluates the homogeneity, which is a dual
measure to completeness. v_measure
evaluates the harmonic mean of
completeness and homogeneity.
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering completeness(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering completeness(true, pred)
Compute the contingency table for a predicted clustering given a ground truth clustering.
contingency_table_clusters(true, pred)
contingency_table_clusters(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
Returns a table (stored as a sparse matrix) such that
counts the number of elements assigned to
cluster
in
pred
and cluster in
true
.
eval_report_clusters
computes common evaluation measures derived
from the output of this function.
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering contingency_table_clusters(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering contingency_table_clusters(true, pred)
Compute the binary contingency table for a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
contingency_table_pairs( true_pairs, pred_pairs, num_pairs = NULL, ordered = FALSE )
contingency_table_pairs( true_pairs, pred_pairs, num_pairs = NULL, ordered = FALSE )
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
num_pairs |
the total number of coreferent and non-coreferent pairs,
excluding equivalent pairs with reversed ids. If not provided,
the true negative cell will be set to |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
Returns a contingency table of the form:
Truth Prediction TRUE FALSE TRUE TP FP FALSE FN TN
The membership_to_pairs
and clusters_to_pairs
functions can be
used to transform other clustering representations into lists of pairs,
as required by this function.
The eval_report_pairs
function computes common evaluation measures
derived from binary contingency matrices, like the ones output by this
function.
### Example where pairs/edges are undirected # ground truth is 3-clique true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # prediction misses one edge pred_pairs <- rbind(c(1,2), c(2,3)) # total number of pairs assuming 3 elements num_pairs <- 3 * (3 - 1) / 2 eval_report_pairs(true_pairs, pred_pairs, num_pairs) ### Example where pairs/edges are directed # ground truth is a 3-star true_pairs <- rbind(c(2,1), c(3,1), c(4,1)) # prediction gets direction of one edge incorrect pred_pairs <- rbind(c(2,1), c(3,1), c(1,4)) # total number of pairs assuming 4 elements num_pairs <- 4 * 4 eval_report_pairs(true_pairs, pred_pairs, num_pairs, ordered = TRUE)
### Example where pairs/edges are undirected # ground truth is 3-clique true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # prediction misses one edge pred_pairs <- rbind(c(1,2), c(2,3)) # total number of pairs assuming 3 elements num_pairs <- 3 * (3 - 1) / 2 eval_report_pairs(true_pairs, pred_pairs, num_pairs) ### Example where pairs/edges are directed # ground truth is a 3-star true_pairs <- rbind(c(2,1), c(3,1), c(4,1)) # prediction gets direction of one edge incorrect pred_pairs <- rbind(c(2,1), c(3,1), c(1,4)) # total number of pairs assuming 4 elements num_pairs <- 4 * 4 eval_report_pairs(true_pairs, pred_pairs, num_pairs, ordered = TRUE)
Compute various evaluation measures for a predicted clustering using a ground truth clustering as a reference.
eval_report_clusters(true, pred)
eval_report_clusters(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
Returns a list containing the following measures:
see homogeneity
see completeness
see v_measure
see rand_index
see adj_rand_index
see variation_info
see mutual_info
see fowlkes_mallows
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering eval_report_clusters(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering eval_report_clusters(true, pred)
Compute various evaluation measures for a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
eval_report_pairs(true_pairs, pred_pairs, num_pairs = NULL, ordered = FALSE)
eval_report_pairs(true_pairs, pred_pairs, num_pairs = NULL, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
num_pairs |
the total number of coreferent and non-coreferent pairs,
excluding equivalent pairs with reversed ids. If not provided,
measures that depend on the number of true negatives will be returned
as |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
Returns a list containing the following measures:
see precision_pairs
see recall_pairs
see f_measure_pairs
see accuracy_pairs
The contingency_table_pairs
function can be used to compute
the contingency table for entity resolution or record linkage problems.
### Example where pairs/edges are undirected # ground truth is 3-clique true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # prediction misses one edge pred_pairs <- rbind(c(1,2), c(2,3)) # total number of pairs assuming 3 elements num_pairs <- 3 * (3 - 1) / 2 eval_report_pairs(true_pairs, pred_pairs, num_pairs) ### Example where pairs/edges are directed # ground truth is a 3-star true_pairs <- rbind(c(2,1), c(3,1), c(4,1)) # prediction gets direction of one edge incorrect pred_pairs <- rbind(c(2,1), c(3,1), c(1,4)) # total number of pairs assuming 4 elements num_pairs <- 4 * 4 eval_report_pairs(true_pairs, pred_pairs, num_pairs, ordered = TRUE)
### Example where pairs/edges are undirected # ground truth is 3-clique true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # prediction misses one edge pred_pairs <- rbind(c(1,2), c(2,3)) # total number of pairs assuming 3 elements num_pairs <- 3 * (3 - 1) / 2 eval_report_pairs(true_pairs, pred_pairs, num_pairs) ### Example where pairs/edges are directed # ground truth is a 3-star true_pairs <- rbind(c(2,1), c(3,1), c(4,1)) # prediction gets direction of one edge incorrect pred_pairs <- rbind(c(2,1), c(3,1), c(1,4)) # total number of pairs assuming 4 elements num_pairs <- 4 * 4 eval_report_pairs(true_pairs, pred_pairs, num_pairs, ordered = TRUE)
Computes the F-measure (a.k.a. F-score) of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
f_measure_pairs(true_pairs, pred_pairs, beta = 1, ordered = FALSE)
f_measure_pairs(true_pairs, pred_pairs, beta = 1, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
beta |
non-negative weight. A value of 0 assigns no weight to recall (i.e. the measure reduces to precision), while larger values assign increasing weight to recall. A value of 1 weights precision and recall equally. |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The -weighted F-measure is defined as the weighted
harmonic mean of precision
and recall
:
Van Rijsbergen, C. J. "Information Retrieval." (2nd ed.). Butterworth-Heinemann, USA, (1979).
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements f_measure_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements f_measure_pairs(true_pairs, pred_pairs, num_pairs)
Computes the Fowlkes-Mallows index between two clusterings, such as a predicted and ground truth clustering.
fowlkes_mallows(true, pred)
fowlkes_mallows(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
The Fowlkes-Mallows index is defined as the geometric mean of precision and recall, computed with respect to pairs of elements.
Fowlkes, E. B. and Mallows, C. L. "A Method for Comparing Two Hierarchical Clusterings." Journal of the American Statistical Association 78:383, 553-569, (1983). doi:10.1080/01621459.1983.10478008
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering fowlkes_mallows(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering fowlkes_mallows(true, pred)
Computes the Fowlkes-Mallows index for a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
fowlkes_mallows_pairs(true_pairs, pred_pairs, ordered = FALSE)
fowlkes_mallows_pairs(true_pairs, pred_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The Fowlkes-Mallows index is defined as the geometric mean of
precision and recall
:
Fowlkes, E. B. and Mallows, C. L. "A Method for Comparing Two Hierarchical Clusterings." Journal of the American Statistical Association 78:383, 553-569, (1983). doi:10.1080/01621459.1983.10478008.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements fowlkes_mallows_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements fowlkes_mallows_pairs(true_pairs, pred_pairs, num_pairs)
Computes the homogeneity between two clusterings, such as a predicted and ground truth clustering.
homogeneity(true, pred)
homogeneity(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
Homogeneity is an entropy-based measure of the similarity
between two clusterings, say and
. The homogeneity
is high if clustering
only assigns members of a cluster to
a single cluster in
. The homogeneity ranges between 0
and 1, where 1 indicates a perfect homogeneity.
Rosenberg, A. and Hirschberg, J. "V-measure: A conditional entropy-based external cluster evaluation measure." Proceedings of the 2007 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning (EMNLP-CoNLL), (2007).
completeness
evaluates the completeness, which is a dual
measure to homogeneity. v_measure
evaluates the harmonic mean of
completeness and homogeneity.
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering homogeneity(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering homogeneity(true, pred)
Computes the mutual information between two clusterings, such as a predicted and ground truth clustering.
mutual_info(true, pred, base = exp(1))
mutual_info(true, pred, base = exp(1))
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
base |
base of the logarithm. Defaults to |
Mutual information is an entropy-based measure of the similarity between two clusterings.
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering mutual_info(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering mutual_info(true, pred)
Computes the precision of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
precision_pairs(true_pairs, pred_pairs, ordered = FALSE)
precision_pairs(true_pairs, pred_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The precision is defined as:
where is the set of true coreferent pairs and
is the
set of predicted coreferent pairs.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements precision_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements precision_pairs(true_pairs, pred_pairs, num_pairs)
Computes the Rand index (RI) between two clusterings, such as a predicted and ground truth clustering.
rand_index(true, pred)
rand_index(true, pred)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
The Rand index (RI) can be expressed as:
where
is the number of elements,
is the number of pairs of elements that appear in the
same cluster in both clusterings, and
is the number of pairs of elements that appear in distinct
clusters in both clusterings.
The RI takes on values between 0 and 1, where 1 denotes exact agreement between the clusterings and 0 denotes disagreement on all pairs of elements.
Rand, W. M. "Objective Criteria for the Evaluation of Clustering Methods." Journal of the American Statistical Association 66(336), 846-850 (1971). doi:10.1080/01621459.1971.10482356
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering rand_index(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering rand_index(true, pred)
Computes the precision of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
recall_pairs(true_pairs, pred_pairs, ordered = FALSE) sensitivity_pairs(true_pairs, pred_pairs, ordered = FALSE)
recall_pairs(true_pairs, pred_pairs, ordered = FALSE) sensitivity_pairs(true_pairs, pred_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The recall is defined as:
where is the set of true coreferent pairs and
is the
set of predicted coreferent pairs.
sensitivity_pairs
is an alias for recall_pairs
.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements recall_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements recall_pairs(true_pairs, pred_pairs, num_pairs)
Computes the specificity of a set of predicted coreferent (linked) pairs given a set of ground truth coreferent pairs.
specificity_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
specificity_pairs(true_pairs, pred_pairs, num_pairs, ordered = FALSE)
true_pairs |
set of true coreferent pairs stored in a matrix or data.frame, where rows index pairs and columns index the ids of the constituents. Any pairs not included are assumed to be non-coreferent. Duplicate pairs (including equivalent pairs with reversed ids) are automatically removed. |
pred_pairs |
set of predicted coreferent pairs, following the same
specification as |
num_pairs |
the total number of coreferent and non-coreferent pairs, excluding equivalent pairs with reversed ids. |
ordered |
whether to treat the element pairs as ordered—i.e. whether
pair |
The specificity is defined as:
where is the set of true non-coreferent pairs,
is the
set of predicted non-coreferent pairs.
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements specificity_pairs(true_pairs, pred_pairs, num_pairs)
true_pairs <- rbind(c(1,2), c(2,3), c(1,3)) # ground truth is 3-clique pred_pairs <- rbind(c(1,2), c(2,3)) # prediction misses one edge num_pairs <- 3 # assuming 3 elements specificity_pairs(true_pairs, pred_pairs, num_pairs)
Computes the V-measure between two clusterings, such as a predicted and ground truth clustering.
v_measure(true, pred, beta = 1)
v_measure(true, pred, beta = 1)
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
beta |
non-negative weight. A value of 0 assigns no weight to completeness (i.e. the measure reduces to homogeneity), while larger values assign increasing weight to completeness. A value of 1 weights completeness and homogeneity equally. |
V-measure is defined as the -weighted harmonic
mean of homogeneity
and completeness
:
The range of V-measure is between 0 and 1, where 1 corresponds to a perfect match between the clusterings. It is equivalent to the normalised mutual information, when the aggregation function is the arithmetic mean.
Rosenberg, A. and Hirschberg, J. "V-measure: A conditional entropy-based external cluster evaluation measure." Proceedings of the 2007 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning (EMNLP-CoNLL), (2007).
Becker, H. "Identification and characterization of events in social media." PhD dissertation, Columbia University, (2011).
homogeneity
and completeness
evaluate the component
measures upon which this measure is based.
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering v_measure(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering v_measure(true, pred)
Computes the variation of information between two clusterings, such as a predicted and ground truth clustering.
variation_info(true, pred, base = exp(1))
variation_info(true, pred, base = exp(1))
true |
ground truth clustering represented as a membership vector. Each entry corresponds to an element and the value identifies the assigned cluster. The specific values of the cluster identifiers are arbitrary. |
pred |
predicted clustering represented as a membership vector. |
base |
base of the logarithm. Defaults to |
Variation of information is an entropy-based distance metric
on the space of clusterings. It is unnormalized and varies between
and
where
is the number of
clustered elements. Larger values of the distance metric correspond
to greater dissimilarity between the clusterings.
Arabie, P. and Boorman, S. A. "Multidimensional scaling of measures of distance between partitions." Journal of Mathematical Psychology 10:2, 148-203, (1973). doi:10.1016/0022-2496(73)90012-6
Meilă, M. "Comparing Clusterings by the Variation of Information." In: Learning Theory and Kernel Machines, Lecture Notes in Computer Science 2777, Springer, Berlin, Heidelberg, (2003). doi:10.1007/978-3-540-45167-9_14
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering variation_info(true, pred)
true <- c(1,1,1,2,2) # ground truth clustering pred <- c(1,1,2,2,2) # predicted clustering variation_info(true, pred)