@@ -0,0 +1,1820 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A# This script takes confusion matrices from the standard input%0A# in the form:%0A#%0A# title%5Ctcol1name%5Ctcol2name%5Ctcol3name%0A# row1name%5Ctfreq11%5Ctfreq12%5Cfreq13%0A# row2name%5Ctfreq21%5Ctfreq22%5Cfreq23%0A#%0A# where %5Ct means TAB separation and there can be as many rows/columns as you%0A# like.%0A#%0A# From the matrices it will compute common statistics to measure classification%0A# accuracy and output them in the input file order.%0A#%0A# Conventions:%0A# a) First upper left cell can hold a title (any string)%0A# b) There is a special class name that will be ignored in some of the%0A#    statistics (defaults to empty string %22%22)%0A# c) Any empty line marks the end of the last matrix and following lines are%0A#    interpreted as a new matrix.%0A# d) Lines starting with %22#%22 are considered comments and are allowed anywhere%0A#    but inside the matrices %0A%0Afrom sys import argv, stdout, stderr, stdin, exit%0Afrom classevaltools import parseConfusionMatrix%0Afrom math import ceil%0A%0A%0Adef usage():%0A    print %3E%3E stderr, 'Usage: ', argv%5B0%5D, '%5B--ignore-class name_of_reject_class %5D %3C matrices.cmat'%0A%0A%0Aif __name__ == %22__main__%22:%0A    import getopt%0A%0A    # parse command line options%0A    try:%0A        opts, args = getopt.getopt(argv%5B1:%5D, 'hi:', %5B'help', 'ignore-class='%5D)%0A    except getopt.GetoptError, err:%0A        print str(err) # will print something like %22option -a not recognized%22%0A        usage()%0A        exit(2)%0A%0A    ignore_class = %22%22%0A    truncate = 1.%0A%0A    for o, a in opts:%0A        if o in (%22-h%22, %22--help%22):%0A            usage()%0A            exit()%0A        elif o in (%22-i%22, %22--ignore-class%22):%0A            ignore_class = a%0A        else:%0A            assert False, %22unhandled option%22%0A%0A    print %22instance%5Cttotal entropy%22%0A%0A    for cmat in parseConfusionMatrix(stdin):%0A        print %22%25s%5Ct%25.2f%22 %25 (cmat.title, cmat.entropy())%0A

Create cmat2entropy.py