def __str__(self):
        """Print Confusion Matrix in table form"""
        o = "== Confusion Matrix == (hor: goals, vert: observations)\n\n"

        keys = set()
        for goalkey,observationkey in self._count.keys():
            keys.add(goalkey)
            keys.add(observationkey)
        keys = sorted( keys)

        linemask = "%20s"
        cells = ['']
        for keyH in keys:
                l = len(keyH)
                if l < 4:
                    l = 4
                elif l > 15:
                    l = 15

                linemask += " %" + str(l) + "s"
                cells.append(keyH)
        linemask += "\n"
        o += linemask % tuple(cells)

        for keyV in keys:
            linemask = "%20s"
            cells = [keyV]
            for keyH in keys:
                l = len(keyH)
                if l < 4:
                    l = 4
                elif l > 15:
                    l = 15
                linemask += " %" + str(l) + "d"
                try:
                    count = self._count[(keyH, keyV)]
                except:
                    count = 0
                cells.append(count)
            linemask += "\n"
            o += linemask % tuple(cells)

        return o
def __str__ ( self ) : o = "== Confusion Matrix == (hor: goals, vert: observations)\n\n" keys = set ( ) for goalkey , observationkey in self . _count . keys ( ) : keys . add ( goalkey ) keys . add ( observationkey ) keys = sorted ( keys ) linemask = "%20s" cells = [ '' ] for keyH in keys : l = len ( keyH ) if l < 4 : l = 4 elif l > 15 : l = 15 linemask += " %" + str ( l ) + "s" cells . append ( keyH ) linemask += "\n" o += linemask % tuple ( cells ) for keyV in keys : linemask = "%20s" cells = [ keyV ] for keyH in keys : l = len ( keyH ) if l < 4 : l = 4 elif l > 15 : l = 15 linemask += " %" + str ( l ) + "d" try : count = self . _count [ ( keyH , keyV ) ] except : count = 0 cells . append ( count ) linemask += "\n" o += linemask % tuple ( cells ) return o
Print Confusion Matrix in table form