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

Class weka.classifiers.CostSensitiveClassifier

java.lang.Object
    |
    +----weka.classifiers.Classifier
            |
            +----weka.classifiers.CostSensitiveClassifier

public class CostSensitiveClassifier
extends Classifier
implements OptionHandler, Drawable
This metaclassifier makes its base classifier cost-sensitive. Two methods can be used to introduce cost-sensitivity: reweighting training instances according to the total cost assigned to each class; or predicting the class with minimum expected misclassification cost (rather than the most likely class). The minimum expected cost approach requires that the base classifier be a DistributionClassifier.

Valid options are:

-M
Minimize expected misclassification cost. The base classifier must produce probability estimates i.e. a DistributionClassifier). (default is to reweight training instances according to costs per class)

-W classname
Specify the full class name of a classifier (required).

-C cost file
File name of a cost matrix to use. If this is not supplied, a cost matrix will be loaded on demand. The name of the on-demand file is the relation name of the training data plus ".cost", and the path to the on-demand file is specified with the -D option.

-D directory
Name of a directory to search for cost files when loading costs on demand (default current directory).

-S seed
Random number seed used when reweighting by resampling (default 1).

Options after -- are passed to the designated classifier.

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

Variable Index

 o MATRIX_ON_DEMAND
 
 o MATRIX_SUPPLIED
 
 o TAGS_MATRIX_SOURCE
 

Constructor Index

 o CostSensitiveClassifier()
 

Method Index

 o buildClassifier(Instances)
Builds the model of the base learner.
 o classifierTipText()
 
 o classifyInstance(Instance)
Classifies a given instance by choosing the class with the minimum expected misclassification cost.
 o costMatrixSourceTipText()
 
 o costMatrixTipText()
 
 o getClassifier()
Gets the classifier used.
 o getCostMatrix()
Gets the misclassification cost matrix.
 o getCostMatrixSource()
Gets the source location method of the cost matrix.
 o getMinimizeExpectedCost()
Gets the value of MinimizeExpectedCost.
 o getOnDemandDirectory()
Returns the directory that will be searched for cost files when loading on demand.
 o getOptions()
Gets the current settings of the Classifier.
 o getSeed()
Get seed for resampling.
 o globalInfo()
 
 o graph()
Returns graph describing the classifier (if possible).
 o listOptions()
Returns an enumeration describing the available options
 o main(String[])
Main method for testing this class.
 o minimizeExpectedCostTipText()
 
 o onDemandDirectoryTipText()
 
 o seedTipText()
 
 o setClassifier(Classifier)
Sets the distribution classifier
 o setCostMatrix(CostMatrix)
Sets the misclassification cost matrix.
 o setCostMatrixSource(SelectedTag)
Sets the source location of the cost matrix.
 o setMinimizeExpectedCost(boolean)
Set the value of MinimizeExpectedCost.
 o setOnDemandDirectory(File)
Sets the directory that will be searched for cost files when loading on demand.
 o setOptions(String[])
Parses a given list of options.
 o setSeed(int)
Set seed for resampling.
 o toString()
Output a representation of this classifier

Field Detail

 o MATRIX_ON_DEMAND
public static final int MATRIX_ON_DEMAND
 o MATRIX_SUPPLIED
public static final int MATRIX_SUPPLIED
 o TAGS_MATRIX_SOURCE
public static final Tag[] TAGS_MATRIX_SOURCE

Constructor Detail

 o CostSensitiveClassifier
public CostSensitiveClassifier()

Method Detail

 o listOptions
public java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
Returns:
an enumeration of all the available options
 o setOptions
public void setOptions(java.lang.String options[]) throws java.lang.Exception
          Parses a given list of options. Valid options are:

-M
Minimize expected misclassification cost. The base classifier must produce probability estimates i.e. a DistributionClassifier). (default is to reweight training instances according to costs per class)

-W classname
Specify the full class name of a classifier (required).

-C cost file
File name of a cost matrix to use. If this is not supplied, a cost matrix will be loaded on demand. The name of the on-demand file is the relation name of the training data plus ".cost", and the path to the on-demand file is specified with the -D option.

-D directory
Name of a directory to search for cost files when loading costs on demand (default current directory).

-S seed
Random number seed used when reweighting by resampling (default 1).

Options after -- are passed to the designated classifier.

Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported
 o getOptions
public java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
Returns:
an array of strings suitable for passing to setOptions
 o globalInfo
public java.lang.String globalInfo()
Returns:
a description of the classifier suitable for displaying in the explorer/experimenter gui
 o costMatrixSourceTipText
public java.lang.String costMatrixSourceTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getCostMatrixSource
public SelectedTag getCostMatrixSource()
          Gets the source location method of the cost matrix. Will be one of MATRIX_ON_DEMAND or MATRIX_SUPPLIED.
Returns:
the cost matrix source.
 o setCostMatrixSource
public void setCostMatrixSource(SelectedTag newMethod)
          Sets the source location of the cost matrix. Values other than MATRIX_ON_DEMAND or MATRIX_SUPPLIED will be ignored.
Parameters:
newMethod - the cost matrix location method.
 o onDemandDirectoryTipText
public java.lang.String onDemandDirectoryTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getOnDemandDirectory
public java.io.File getOnDemandDirectory()
          Returns the directory that will be searched for cost files when loading on demand.
Returns:
The cost file search directory.
 o setOnDemandDirectory
public void setOnDemandDirectory(java.io.File newDir)
          Sets the directory that will be searched for cost files when loading on demand.
Parameters:
newDir - The cost file search directory.
 o minimizeExpectedCostTipText
public java.lang.String minimizeExpectedCostTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getMinimizeExpectedCost
public boolean getMinimizeExpectedCost()
          Gets the value of MinimizeExpectedCost.
Returns:
Value of MinimizeExpectedCost.
 o setMinimizeExpectedCost
public void setMinimizeExpectedCost(boolean newMinimizeExpectedCost)
          Set the value of MinimizeExpectedCost.
Parameters:
newMinimizeExpectedCost - Value to assign to MinimizeExpectedCost.
 o classifierTipText
public java.lang.String classifierTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o setClassifier
public void setClassifier(Classifier classifier)
          Sets the distribution classifier
Parameters:
classifier - the classifier with all options set.
 o getClassifier
public Classifier getClassifier()
          Gets the classifier used.
Returns:
the classifier
 o costMatrixTipText
public java.lang.String costMatrixTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getCostMatrix
public CostMatrix getCostMatrix()
          Gets the misclassification cost matrix.
Returns:
the cost matrix
 o setCostMatrix
public void setCostMatrix(CostMatrix newCostMatrix)
          Sets the misclassification cost matrix.
Parameters:
the - cost matrix
 o seedTipText
public java.lang.String seedTipText()
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o setSeed
public void setSeed(int seed)
          Set seed for resampling.
Parameters:
seed - the seed for resampling
 o getSeed
public int getSeed()
          Get seed for resampling.
Returns:
the seed for resampling
 o buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
          Builds the model of the base learner.
Parameters:
data - the training data
Throws:
java.lang.Exception - if the classifier could not be built successfully
Overrides:
buildClassifier in class Classifier
 o classifyInstance
public double classifyInstance(Instance instance) throws java.lang.Exception
          Classifies a given instance by choosing the class with the minimum expected misclassification cost.
Parameters:
instance - the instance to be classified
Throws:
java.lang.Exception - if instance could not be classified successfully
Overrides:
classifyInstance in class Classifier
 o graph
public java.lang.String graph() throws java.lang.Exception
          Returns graph describing the classifier (if possible).
Returns:
the graph of the classifier in dotty format
Throws:
java.lang.Exception - if the classifier cannot be graphed
 o toString
public java.lang.String toString()
          Output a representation of this classifier
Overrides:
toString in class java.lang.Object
 o main
public static void main(java.lang.String argv[])
          Main method for testing this class.
Parameters:
argv - should contain the following arguments: -t training file [-T test file] [-c class index]

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