Created
March 9, 2015 16:41
-
-
Save terrycojones/69ad2207f503ce682c0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Counter, defaultdict | |
class ConfusionMatrix(object): | |
def __init__(self, trueLabels, clusterLabels): | |
self._counts = defaultdict(Counter) | |
self.allLabels = set(trueLabels + clusterLabels) | |
for trueLabel, clusterLabel in zip(trueLabels, clusterLabels): | |
self._counts[trueLabel][clusterLabel] += 1 | |
def __getitem__(self, item): | |
return self._counts[item[0]][item[1]] | |
def __setitem__(self, item, value): | |
self._counts[item[0]][item[1]] = value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initialization is
With access like:
and all labels are available: