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 a misclassification cost matrix. The element in the i'th column of the j'th row is the cost for misclassifying an instance of class j as having class i.

Version:
$Revision: 1.2 $
Author:
Len Trigg (len@intelligenesis.net)

Constructor Index

 o CostMatrix(CostMatrix)
 o CostMatrix(int)
Creates a default cost matrix for the given number of classes.
 o CostMatrix(Reader)
Creates a cost matrix from a cost file.

Method Index

 o applyCostMatrix(Instances, Random)
Changes the dataset to reflect a given set of costs.
 o expectedCosts(double[])
Calculates the expected misclassification cost for each possible class value, given class probability estimates.
 o getMaxCost(int)
Gets the maximum misclassification cost possible for a given actual class value
 o initialize()
Sets the costs to default values (i.e.
 o readOldFormat(Reader)
Reads misclassification cost matrix from given reader.
 o size()
Gets the number of classes.

Constructors

 o CostMatrix
 public CostMatrix(CostMatrix toCopy)
 o CostMatrix
 public CostMatrix(int numClasses)
Creates a default cost matrix for the given number of classes. The default misclassification cost is 1.

Parameters:
numClasses - the number of classes
 o CostMatrix
 public CostMatrix(Reader r) throws Exception
Creates a cost matrix from a cost file.

Parameters:
r - a reader from which the cost matrix will be read
Throws: Exception
if an error occurs

Methods

 o readOldFormat
 public void readOldFormat(Reader reader) throws Exception
Reads misclassification cost matrix from given reader. Each line has to contain three numbers: the index of the true class, the index of the incorrectly assigned class, and the weight, separated by white space characters. Comments can be appended to the end of a line by using the '%' character.

Parameters:
reader - the reader from which the cost matrix is to be read
Throws: Exception
if the cost matrix does not have the right format
 o initialize
 public void initialize()
Sets the costs to default values (i.e. 0 down the diagonal, and 1 for any misclassification).

Overrides:
initialize in class Matrix
 o size
 public int size()
Gets the number of classes.

Returns:
the number of classes
 o applyCostMatrix
 public Instances applyCostMatrix(Instances instances,
                                  Random random) throws Exception
Changes the dataset to reflect a given set of costs. Sets the weights of instances according to the misclassification cost matrix, or does resampling according to the cost matrix (if a random number generator is provided). Returns a new dataset.

Parameters:
instances - the instances to apply cost weights to.
random - a random number generator
Returns:
the new dataset
Throws: Exception
if the cost matrix does not have the right format
 o expectedCosts
 public double[] expectedCosts(double probabilities[]) throws Exception
Calculates the expected misclassification cost for each possible class value, given class probability estimates.

Parameters:
probabilities - an array containing probability estimates for each class value.
Returns:
an array containing the expected misclassification cost for each class.
Throws: Exception
if the number of probabilities does not match the number of classes.
 o getMaxCost
 public double getMaxCost(int actualClass)
Gets the maximum misclassification cost possible for a given actual class value

Parameters:
actualClass - the index of the actual class value
Returns:
the highest cost possible for misclassifying this class

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