net.sourceforge.nite.datainspection.calc
Class ConfusionMatrix

java.lang.Object
  extended by net.sourceforge.nite.datainspection.calc.ConfusionMatrix

public class ConfusionMatrix
extends java.lang.Object

This class ConfusionMatrix has methods for comparing Two Classifications. Both classifications must contain exactly the same items in the same order.
encapsulates a square matrix of double with row and column names.
Rows and Column names are unique Values that occur in the ordered list of values
confusion matrix contains double entries for each pair of Values in the ordered list of class labels (Values)
confusion(rowValue,colValue) = the (weighted) count of times that rowValue was confused with colValue
a confusion matrix is not nec. symmetrical.
kappaCohen - according to Cohen(1966) - see: Di Eugenio in: Comput. Ling. 2004, Vol.30, nr.1

See Also:
Classification

Constructor Summary
ConfusionMatrix(Classification f, Classification s)
          construct a confusion matrix from the given Classifications condition: f and s are equally long and agree on items that have been classified.
ConfusionMatrix(double[][] matrix)
          create Confusion Matrix with the given matrix as entries the ordered list of values (class labels) is : 0,1,2,...,matrix.length-1
ConfusionMatrix(double[][] matrix, java.util.List vals)
          create Confusion Matrix with the given matrix as entries and the given list as class labels assumes ordering of labels in list and matrix columns and rows are equal.
ConfusionMatrix(int size)
          creates an empty confusion matrix of given size with default values the numbers (0,1,...,size-1)
ConfusionMatrix(java.util.List values)
           
 
Method Summary
 void add(Value rowValue, Value colValue)
           
 double entry(int row, int col)
           
 double entry(Value rowValue, Value colValue)
           
 Value getValue(int n)
           
 java.util.List getValues()
           
 double kappa()
          kappa is computed using the confusion matrix method: Cohen - see also Di Eugenio and Glass in Comput.
static void main(java.lang.String[] args)
           
 int numberOfValues()
           
 void printMatrix(java.io.PrintWriter pw)
           
 void printMatrix(java.lang.String filename)
           
 void printValues(java.io.PrintWriter pw)
          print all Values in list values on given PrintWriter
static ConfusionMatrix readCSVFile(java.io.BufferedReader reader, int counter)
          create and return a ConfusionMatrix from the data in a CSV file format: labelName1;x;x;x;x;x;x labelName2;x;x;x;x;x;x ...
 void setEntry(int row, int col, double cv)
           
 void setEntry(Value rowValue, Value colValue, double cv)
          set confusion[rowValue][colValue] to cv
 void setValues(java.util.List vals)
          set the list of class labels used the order should be the same as the order of Values in the row and columns of the matrix
 void showValues()
          print all Values that occur in first or second on SO
 int size()
          size() equals numberOfValues()
 java.lang.String toString()
           
 double totalColumn(int i)
           
 double totalItems()
           
 double totalRow(int i)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfusionMatrix

public ConfusionMatrix(Classification f,
                       Classification s)
construct a confusion matrix from the given Classifications condition: f and s are equally long and agree on items that have been classified. moreover: items (units) occur in the same order in both classifications


ConfusionMatrix

public ConfusionMatrix(double[][] matrix)
create Confusion Matrix with the given matrix as entries the ordered list of values (class labels) is : 0,1,2,...,matrix.length-1


ConfusionMatrix

public ConfusionMatrix(double[][] matrix,
                       java.util.List vals)
create Confusion Matrix with the given matrix as entries and the given list as class labels assumes ordering of labels in list and matrix columns and rows are equal.

Parameters:
matrix - the entries of the confusion matrix
values - the ordered list of class labels

ConfusionMatrix

public ConfusionMatrix(int size)
creates an empty confusion matrix of given size with default values the numbers (0,1,...,size-1)


ConfusionMatrix

public ConfusionMatrix(java.util.List values)
Method Detail

entry

public double entry(int row,
                    int col)
Returns:
confusion[row][col]

entry

public double entry(Value rowValue,
                    Value colValue)
Returns:
confusion[rowValue][colValue]

setValues

public void setValues(java.util.List vals)
set the list of class labels used the order should be the same as the order of Values in the row and columns of the matrix


setEntry

public void setEntry(Value rowValue,
                     Value colValue,
                     double cv)
set confusion[rowValue][colValue] to cv


setEntry

public void setEntry(int row,
                     int col,
                     double cv)

add

public void add(Value rowValue,
                Value colValue)

numberOfValues

public int numberOfValues()

getValues

public java.util.List getValues()
Returns:
the ordered list of Values

getValue

public Value getValue(int n)

printMatrix

public void printMatrix(java.lang.String filename)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printMatrix

public void printMatrix(java.io.PrintWriter pw)

showValues

public void showValues()
print all Values that occur in first or second on SO


printValues

public void printValues(java.io.PrintWriter pw)
print all Values in list values on given PrintWriter


readCSVFile

public static ConfusionMatrix readCSVFile(java.io.BufferedReader reader,
                                          int counter)
create and return a ConfusionMatrix from the data in a CSV file format: labelName1;x;x;x;x;x;x labelName2;x;x;x;x;x;x ... labelNameN;x;x;x;x;x;x

Parameters:
reader -
counter - the number of data columns (size of matrix)

kappa

public double kappa()
kappa is computed using the confusion matrix method: Cohen - see also Di Eugenio and Glass in Comput. Ling. 2004


totalItems

public double totalItems()

totalColumn

public double totalColumn(int i)

totalRow

public double totalRow(int i)

size

public int size()
size() equals numberOfValues()

Returns:
the number of columns (is number of rows) of this confusion matrix

main

public static void main(java.lang.String[] args)