|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weka.core.Matrix | +--weka.classifiers.CostMatrix
Class for a misclassification cost matrix. The element in the i'th column of the j'th row is the cost for (mis)classifying an instance of class j as having class i. It is valid to have non-zero values down the diagonal (these are typically negative to indicate some varying degree of "gain" from making a correct prediction).
Field Summary | |
static java.lang.String |
FILE_EXTENSION
The filename extension that should be used for cost files |
Fields inherited from class weka.core.Matrix |
m_Elements |
Constructor Summary | |
CostMatrix(CostMatrix toCopy)
Creates a cost matrix identical to an existing matrix. |
|
CostMatrix(int numClasses)
Creates a default cost matrix for the given number of classes. |
|
CostMatrix(java.io.Reader r)
Creates a cost matrix from a cost file. |
Method Summary | |
Instances |
applyCostMatrix(Instances instances,
java.util.Random random)
Changes the dataset to reflect a given set of costs. |
double[] |
expectedCosts(double[] probabilities)
Calculates the expected misclassification cost for each possible class value, given class probability estimates. |
double |
getMaxCost(int actualClass)
Gets the maximum misclassification cost possible for a given actual class value |
void |
initialize()
Sets the costs to default values (i.e. |
static void |
main(java.lang.String[] args)
Tests out creation of a frequency dependent cost matrix from the command line. |
static CostMatrix |
makeFrequencyDependentMatrix(Instances instances,
double weight)
Creates a cost matrix for the class attribute of the supplied instances, where the misclassification costs are higher for misclassifying a rare class as a frequent one. |
void |
normalize()
Normalizes the cost matrix so that diagonal elements are zero. |
void |
readOldFormat(java.io.Reader reader)
Reads misclassification cost matrix from given reader. |
int |
size()
Gets the number of classes. |
Methods inherited from class weka.core.Matrix |
add, addElement, clone, getElement, lubksb, ludcmp, multiply, numColumns, numRows, regression, regression, setColumn, setElement, setRow, toString, transpose, write |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static java.lang.String FILE_EXTENSION
Constructor Detail |
public CostMatrix(CostMatrix toCopy)
toCopy
- the matrix to copy.public CostMatrix(int numClasses)
numClasses
- the number of classespublic CostMatrix(java.io.Reader r) throws java.lang.Exception
r
- a reader from which the cost matrix will be readjava.lang.Exception
- if an error occursMethod Detail |
public static CostMatrix makeFrequencyDependentMatrix(Instances instances, double weight) throws java.lang.Exception
instances
- a value of type 'Instances'weight
- a value of type 'double'java.lang.Exception
- if no class attribute is assigned, or the class
attribute is not nominalpublic void readOldFormat(java.io.Reader reader) throws java.lang.Exception
reader
- the reader from which the cost matrix is to be readjava.lang.Exception
- if the cost matrix does not have the
right formatpublic void initialize()
initialize
in class Matrix
public int size()
public void normalize()
2 5
3 -1
becomes
0 3
4 0
This normalization will affect total classification cost during evaluation, but will not affect the decision made by applying minimum expected cost criteria during prediction.
public Instances applyCostMatrix(Instances instances, java.util.Random random) throws java.lang.Exception
instances
- the instances to apply cost weights to.random
- a random number generatorjava.lang.Exception
- if the cost matrix does not have the right
formatpublic double[] expectedCosts(double[] probabilities) throws java.lang.Exception
probabilities
- an array containing probability estimates for each
class value.java.lang.Exception
- if the number of probabilities does not match the
number of classes.public double getMaxCost(int actualClass)
actualClass
- the index of the actual class valuepublic static void main(java.lang.String[] args)
[]args
- a value of type 'String'
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |