Class ClassOrder
java.lang.Object
weka.filters.Filter
weka.filters.supervised.attribute.ClassOrder
- All Implemented Interfaces:
Serializable
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,OptionHandler
,RevisionHandler
,WeightedAttributesHandler
,WeightedInstancesHandler
,SupervisedFilter
public class ClassOrder
extends Filter
implements SupervisedFilter, OptionHandler, WeightedAttributesHandler, WeightedInstancesHandler
Changes the order of the classes so that the class
values are no longer of in the order specified in the header. The values 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.
Valid options are:
-R <seed> Specify the seed of randomization used to randomize the class order (default: 1)
-C <order> Specify the class order to be sorted, could be 0: ascending 1: descending and 2: random.(default: 0)
- Version:
- $Revision: 14508 $
- Author:
- Xin Xu (xx5@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The class values are sorted in ascending order based on their frequenciesstatic final int
The class values are sorted in descending order based on their frequenciesstatic final int
The class values are sorted in random order -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Signify that this batch of input to the filter is finished.Returns the tip text for this propertydouble[]
distributionsByOriginalIndex
(double[] before) Convert the given class distribution back to the distributions with the original internal class indexReturns the Capabilities of this filter.double[]
Get the class distribution of the sorted class values.int
Get the wanted class orderString[]
Gets the current settings of the filter.Returns the revision string.long
getSeed()
Get the current randomization seedReturns a string describing this filterboolean
Input an instance for filtering.Returns an enumeration describing the available options.static void
Main method for testing this class.double
originalValue
(double value) Return the original internal class value given the randomized class value, i.e.Returns the tip text for this propertyvoid
setClassOrder
(int order) Set the wanted class orderboolean
setInputFormat
(Instances instanceInfo) Sets the format of the input instances.void
setOptions
(String[] options) Parses a given list of options.void
setSeed
(long seed) Set randomization seedMethods inherited from class weka.filters.Filter
batchFilterFile, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getOutputFormat, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, toString, useFilter, wekaStaticWrapper
-
Field Details
-
FREQ_ASCEND
public static final int FREQ_ASCENDThe class values are sorted in ascending order based on their frequencies- See Also:
-
FREQ_DESCEND
public static final int FREQ_DESCENDThe class values are sorted in descending order based on their frequencies- See Also:
-
RANDOM
public static final int RANDOMThe class values are sorted in random order- See Also:
-
-
Constructor Details
-
ClassOrder
public ClassOrder()
-
-
Method Details
-
globalInfo
Returns a string describing this filter- Returns:
- a description of the filter suitable for displaying in the explorer/experimenter gui
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classFilter
- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. Valid options are:-R <seed> Specify the seed of randomization used to randomize the class order (default: 1)
-C <order> Specify the class order to be sorted, could be 0: ascending 1: descending and 2: random.(default: 0)
- Specified by:
setOptions
in interfaceOptionHandler
- Overrides:
setOptions
in classFilter
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the filter.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classFilter
- Returns:
- an array of strings suitable for passing to setOptions
-
seedTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getSeed
public long getSeed()Get the current randomization seed- Returns:
- a seed
-
setSeed
public void setSeed(long seed) Set randomization seed- Parameters:
seed
- the set seed
-
classOrderTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getClassOrder
public int getClassOrder()Get the wanted class order- Returns:
- class order
-
setClassOrder
public void setClassOrder(int order) Set the wanted class order- Parameters:
order
- the class order
-
getCapabilities
Returns the Capabilities of this filter.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classFilter
- Returns:
- the capabilities of this object
- See Also:
-
setInputFormat
Sets the format of the input instances.- Overrides:
setInputFormat
in classFilter
- 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
- Throws:
Exception
- if no class index set or class not nominal
-
input
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.- Overrides:
input
in classFilter
- Parameters:
instance
- the input instance- Returns:
- true if the filtered instance may now be collected with output().
- Throws:
IllegalStateException
- if no input format has been defined.
-
batchFinished
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- Overrides:
batchFinished
in classFilter
- Returns:
- true if there are instances pending output
- Throws:
IllegalStateException
- if no input structure has been defined,Exception
- if there was a problem finishing the batch.
-
getClassCounts
public double[] getClassCounts()Get the class distribution of the sorted class values. If class is numeric it returns null- Returns:
- the class counts
-
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
-
originalValue
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:
Exception
- if the coverter table is not set yet
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classFilter
- Returns:
- the revision
-
main
Main method for testing this class.- Parameters:
argv
- should contain arguments to the filter: use -h for help
-