View source: R/maximise-trace.R
maximise_trace | R Documentation |
Maximising the trace of a matrix amounts to maximising the diagonal elements. This is useful when comparing clustering methods, or comparing clustering results with known ground truth labels.
maximise_trace(mat)
mat |
Input matrix |
A matrix with rows permuted such that tr(mat) is maximised.
# say we have the output of a clustering algorithm on 100 samples a <- sample(letters[1:5], 100, replace = TRUE) # now imagine we repeat it and get different labels for the same clusters releveler <- setNames(letters[1:5], sample(letters[1:5])) b <- releveler[a] # comparing the results, it can be hard to spot which cluster is which table(a, b) # if we permute the rows to maximise the trace it's pretty obvious maximise_trace(table(a, b))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.