file = open(outFile, 'w+')
matrix = defaultdict(lambda: defaultdict(int))
for s in range(len(self.goldenTags)):
for w in range(len(self.goldenTags[s])):
matrix[self.goldenTags[s][w].tag][self.myTags[s][w].tag] += 1
I created a nested dictionary that represents a confusion matrix of a POS tagger, and it looks like :
'VBP': defaultdict(<class 'int'>,
{'CD': 4,
'FW': 1,
'JJ': 5,
'JJS': 1,
'NN': 61,
'NNP': 6,
'NNPS': 1,
'SYM': 2,
'UH': 19,
'VB': 72,
'VBD': 5,
'VBG': 2,
'VBP': 537,
'VBZ': 1}),
which is kinda ugly. I want to save this as a neat matrix format into a txt file preferably without using any library. What is a good way to do this?
Tag Tag Tag Tag Tag
Tag 1 0 2 inf 4
Tag 4 2 0 1 5
Tag inf inf 1 0 3
Tag 3 4 5 3 0