All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.classifiers.CostMatrix

java.lang.Object
    |
    +----weka.core.Matrix
            |
            +----weka.classifiers.CostMatrix

public class CostMatrix
extends Matrix
Class for storing and manipulating a misclassification cost matrix. The element at position i,j in the matrix is the penalty for classifying an instance of class j as class i.

Version:
$Revision: 1.9 $
Author:
Richard Kirkby (rkirkby@cs.waikato.ac.nz)

Variable Index

 o FILE_EXTENSION
The deafult file extension for cost matrix files

Constructor Index

 o CostMatrix(CostMatrix)
Creates a cost matrix that is a copy of another.
 o CostMatrix(int)
Creates a default cost matrix of a particular size.
 o CostMatrix(Reader)
Creates a cost matrix from a reader.

Method Index

 o applyCostMatrix(Instances, Random)
Applies the cost matrix to a set of instances.
 o expectedCosts(double[])
Calculates the expected misclassification cost for each possible class value, given class probability estimates.
 o getMaxCost(int)
Gets the maximum cost for a particular class value.
 o initialize()
Sets the cost of all correct classifications to 0, and all misclassifications to 1.
 o normalize()
Normalizes the matrix so that the diagonal contains zeros.
 o readOldFormat(Reader)
Loads a cost matrix in the old format from a reader.
 o size()
Gets the size of the matrix.

Field Detail

 o FILE_EXTENSION
public static java.lang.String FILE_EXTENSION
          The deafult file extension for cost matrix files

Constructor Detail

 o CostMatrix
public CostMatrix(CostMatrix toCopy)
          Creates a cost matrix that is a copy of another.
Parameters:
toCopy - the matrix to copy.
 o CostMatrix
public CostMatrix(int numOfClasses)
          Creates a default cost matrix of a particular size. All values will be 0.
Parameters:
numOfClasses - the number of classes that the cost matrix holds.
 o CostMatrix
public CostMatrix(java.io.Reader reader) throws java.lang.Exception
          Creates a cost matrix from a reader.
Parameters:
reader - the reader to get the values from.
Throws:
java.lang.Exception - if the matrix is invalid.

Method Detail

 o initialize
public void initialize()
          Sets the cost of all correct classifications to 0, and all misclassifications to 1.
 o size
public int size()
          Gets the size of the matrix.
Returns:
the size.
 o applyCostMatrix
public Instances applyCostMatrix(Instances data,
                                 java.util.Random random) throws java.lang.Exception
          Applies the cost matrix to a set of instances. If a random number generator is supplied the instances will be resampled, otherwise they will be rewighted. Adapted from code once sitting in Instances.java
Parameters:
data - the instances to reweight.
random - a random number generator for resampling, if null then instances are rewighted.
Returns:
a new dataset reflecting the cost of misclassification.
Throws:
java.lang.Exception - if the data has no class or the matrix in inappropriate.
 o expectedCosts
public double[] expectedCosts(double classProbs[]) throws java.lang.Exception
          Calculates the expected misclassification cost for each possible class value, given class probability estimates.
Parameters:
classProbs - the class probability estimates.
Returns:
the expected costs.
Throws:
java.lang.Exception - if the wrong number of class probabilities is supplied.
 o getMaxCost
public double getMaxCost(int classVal)
          Gets the maximum cost for a particular class value.
Parameters:
classVal - the class value.
Returns:
the maximum cost.
 o normalize
public void normalize()
          Normalizes the matrix so that the diagonal contains zeros.
 o readOldFormat
public void readOldFormat(java.io.Reader reader) throws java.lang.Exception
          Loads a cost matrix in the old format from a reader. Adapted from code once sitting in Instances.java
Parameters:
reader - the reader to get the values from.
Throws:
java.lang.Exception - if the matrix cannot be read correctly.

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home