Align Cluster Labels to Ground Truth Using Hungarian Algorithm
Source:R/evaluation_wrappers.R
align_clusters_to_truth.RdFinds the optimal mapping from estimated cluster labels to true cluster labels using the Hungarian algorithm. This resolves the label switching problem inherent in clustering.
Value
A list with:
mappingNamed integer vector where names are estimated labels and values are corresponding true labels.
z_alignedInteger vector of aligned estimated labels (same length as z_hat, with labels remapped to match z_true).
accuracyNumeric scalar: proportion of correctly matched assignments after alignment.
Returns a list with all NA values if inputs are invalid.
Details
The Hungarian algorithm (via clue::solve_LSAP) finds the assignment
that maximizes the overlap between estimated and true clusters. This is
essential for fair evaluation of clustering methods where label identities
are arbitrary.
When K_hat != K_true, the algorithm handles the mismatch by:
If K_hat < K_true: Some true clusters may not have a match
If K_hat > K_true: Some estimated clusters map to the same true cluster