Created
March 9, 2015 15:54
-
-
Save terrycojones/220e9bc1bf4fb4d4170d to your computer and use it in GitHub Desktop.
Confusion matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
def confusion(trueLabels, clusterLabels): | |
counts = defaultdict(lambda: defaultdict(int)) | |
allLabels = sorted(set(trueLabels + clusterLabels)) | |
for trueLabel, clusterLabel in zip(trueLabels, clusterLabels): | |
counts[trueLabel][clusterLabel] += 1 | |
return allLabels, counts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage (with ugly printing) looks something like this
Producing