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)
FILE_EXTENSION- The deafult file extension for cost matrix files
CostMatrix(CostMatrix)
- Creates a cost matrix that is a copy of another.
CostMatrix(int)
- Creates a default cost matrix of a particular size.
CostMatrix(Reader)
- Creates a cost matrix from a reader.
applyCostMatrix(Instances, Random)
- Applies the cost matrix to a set of instances.
expectedCosts(double[])
- Calculates the expected misclassification cost for each possible class value,
given class probability estimates.
getMaxCost(int)
- Gets the maximum cost for a particular class value.
initialize()
- Sets the cost of all correct classifications to 0, and all
misclassifications to 1.
normalize()
- Normalizes the matrix so that the diagonal contains zeros.
readOldFormat(Reader)
- Loads a cost matrix in the old format from a reader.
size()
- Gets the size of the matrix.
FILE_EXTENSION
public static java.lang.String FILE_EXTENSION
The deafult file extension for cost matrix files
CostMatrix
public CostMatrix(CostMatrix toCopy)
Creates a cost matrix that is a copy of another.
- Parameters:
toCopy - the matrix to copy.
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.
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.
initialize
public void initialize()
Sets the cost of all correct classifications to 0, and all
misclassifications to 1.
size
public int size()
Gets the size of the matrix.
- Returns:
- the size.
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.
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.
getMaxCost
public double getMaxCost(int classVal)
Gets the maximum cost for a particular class value.
- Parameters:
classVal - the class value.
- Returns:
- the maximum cost.
normalize
public void normalize()
Normalizes the matrix so that the diagonal contains zeros.
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