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

Class weka.filters.supervised.attribute.ClassOrder

java.lang.Object
    |
    +----weka.filters.Filter
            |
            +----weka.filters.supervised.attribute.ClassOrder

public class ClassOrder
extends Filter
implements SupervisedFilter, OptionHandler
A filter that sorts the order of classes so that the class values are no longer of in the order of that in the header file after filtered. The values of the class will be in the order specified by the user -- it could be either in ascending/descending order by the class frequency or in random order.

The format of the header is thus not changed in this filter (although it still uses setInputFormat()), but the class value of each instance is converted to sorted values within the same range. The value can also be converted back using originalValue(double value) procedure.

Version:
$Revision: 1.2 $
Author:
Xin Xu (xx5@cs.waikato.ac.nz)

Variable Index

 o FREQ_ASCEND
The class values are sorted in ascending order based on their frequencies
 o FREQ_DESCEND
The class values are sorted in descending order based on their frequencies
 o RANDOM
The class values are sorted in random order

Constructor Index

 o ClassOrder()
 

Method Index

 o batchFinished()
Signify that this batch of input to the filter is finished.
 o classOrderTipText()
Returns the tip text for this property
 o distributionsByOriginalIndex(double[])
Convert the given class distribution back to the distributions with the original internal class index
 o getClassCounts()
Get the class distribution of the sorted class values.
 o getClassOrder()
Get the wanted class order
 o getOptions()
Gets the current settings of the filter.
 o getSeed()
Get the current randomization seed
 o input(Instance)
Input an instance for filtering.
 o listOptions()
Returns an enumeration describing the available options.
 o main(String[])
Main method for testing this class.
 o originalValue(double)
Return the original internal class value given the randomized class value, i.e.
 o seedTipText()
Returns the tip text for this property
 o setClassOrder(int)
Set the wanted class order
 o setInputFormat(Instances)
Sets the format of the input instances.
 o setOptions(String[])
Parses a given list of options controlling the behaviour of this object.
 o setSeed(long)
Set randomization seed

Field Detail

 o FREQ_ASCEND
public static final int FREQ_ASCEND
          The class values are sorted in ascending order based on their frequencies
 o FREQ_DESCEND
public static final int FREQ_DESCEND
          The class values are sorted in descending order based on their frequencies
 o RANDOM
public static final int RANDOM
          The class values are sorted in random order

Constructor Detail

 o ClassOrder
public ClassOrder()

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 controlling the behaviour of this object. Valid options are:

-R
Specify the seed of randomization used to randomize the class order (default: 1)

-C
Specify the class order to be sorted, could be 0: ascending, 1: descending and 2: random(default: 0)

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 filter.
Returns:
an array of strings suitable for passing to setOptions
 o seedTipText
public java.lang.String seedTipText()
          Returns the tip text for this property
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getSeed
public long getSeed()
          Get the current randomization seed
Returns:
a seed
 o setSeed
public void setSeed(long seed)
          Set randomization seed
Parameters:
seed - the set seed
 o classOrderTipText
public java.lang.String classOrderTipText()
          Returns the tip text for this property
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getClassOrder
public int getClassOrder()
          Get the wanted class order
Returns:
class order
 o setClassOrder
public void setClassOrder(int order)
          Set the wanted class order
Parameters:
order - the class order
 o setInputFormat
public boolean setInputFormat(Instances instanceInfo) throws java.lang.Exception
          Sets the format of the input instances.
Parameters:
instanceInfo - an Instances object containing the input instance structure (any instances contained in the object are ignored - only the structure is required).
Returns:
true if the outputFormat may be collected immediately
Overrides:
setInputFormat in class Filter
 o input
public boolean input(Instance instance)
          Input an instance for filtering. Ordinarily the instance is processed and made available for output immediately. Some filters require all instances be read before producing output.
Parameters:
instance - the input instance
Returns:
true if the filtered instance may now be collected with output().
Throws:
java.lang.IllegalStateException - if no input format has been defined.
Overrides:
input in class Filter
 o batchFinished
public boolean batchFinished() throws java.lang.Exception
          Signify that this batch of input to the filter is finished. If the filter requires all instances prior to filtering, output() may now be called to retrieve the filtered instances. Any subsequent instances filtered should be filtered based on setting obtained from the first batch (unless the inputFormat has been re-assigned or new options have been set). This implementation sorts the class values and provide class counts in the output format
Returns:
true if there are instances pending output
Throws:
NullPointerException - if no input structure has been defined,
java.lang.Exception - if there was a problem finishing the batch.
Overrides:
batchFinished in class Filter
 o getClassCounts
public double[] getClassCounts()
          Get the class distribution of the sorted class values. If class is numeric it returns null
Returns:
the class counts
 o distributionsByOriginalIndex
public double[] distributionsByOriginalIndex(double before[])
          Convert the given class distribution back to the distributions with the original internal class index
Parameters:
before - the given class distribution
Returns:
the distribution converted back
 o originalValue
public double originalValue(double value) throws java.lang.Exception
          Return the original internal class value given the randomized class value, i.e. the string presentations of the two indices are the same. It's useful when the filter is used within a classifier so that the filtering procedure should be transparent to the evaluation
Parameters:
value - the given value
Returns:
the original internal value, -1 if not found
Throws:
if - the coverter table is not set yet
 o main
public static void main(java.lang.String argv[])
          Main method for testing this class.
Parameters:
argv - should contain arguments to the filter: use -h for help

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