Class SubsetByExpression
java.lang.Object
weka.filters.Filter
weka.filters.SimpleFilter
weka.filters.SimpleBatchFilter
weka.filters.unsupervised.instance.SubsetByExpression
- All Implemented Interfaces:
Serializable
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,OptionHandler
,RevisionHandler
,WeightedAttributesHandler
,WeightedInstancesHandler
public class SubsetByExpression
extends SimpleBatchFilter
implements WeightedInstancesHandler, WeightedAttributesHandler
Filters instances according to a user-specified expression.
Examples:
- extracting only mammals and birds from the 'zoo' UCI dataset:
(CLASS is 'mammal') or (CLASS is 'bird')
- extracting only animals with at least 2 legs from the 'zoo' UCI dataset:
(ATT14 >= 2)
- extracting only instances with non-missing 'wage-increase-second-year'
from the 'labor' UCI dataset:
not ismissing(ATT3)
Valid options are:
Examples:
- extracting only mammals and birds from the 'zoo' UCI dataset:
(CLASS is 'mammal') or (CLASS is 'bird')
- extracting only animals with at least 2 legs from the 'zoo' UCI dataset:
(ATT14 >= 2)
- extracting only instances with non-missing 'wage-increase-second-year'
from the 'labor' UCI dataset:
not ismissing(ATT3)
Valid options are:
-E <expr> The expression to use for filtering (default: true).
-F Apply the filter to instances that arrive after the first (training) batch. The default is to not apply the filter (i.e., always return the instance)
-output-debug-info If set, filter is run in debug mode and may output additional info to the console
-do-not-check-capabilities If set, filter capabilities are not checked when input format is set (use with caution).
- Version:
- $Revision: 14508 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the tip text for this property.Returns the tip text for this property.Returns the Capabilities of this filter.Returns the expression used for filtering.boolean
Get whether to apply the filter to instances that arrive once the first (training) batch has been seen.String[]
Gets the current settings of the filter.Returns the revision string.Returns a string describing this filter.boolean
Input an instance for filtering.Returns an enumeration describing the available options.static void
Main method for running this filter.boolean
SubsetByExpression may return false from input() (thus not making an instance available immediately) even after the first batch has been completed if the user has opted to apply the filter to instances after the first batch (rather than just passing them through).void
setExpression
(String value) Sets the expression used for filtering.void
setFilterAfterFirstBatch
(boolean b) Set whether to apply the filter to instances that arrive once the first (training) batch has been seen.void
setOptions
(String[] options) Parses a given list of options.Methods inherited from class weka.filters.SimpleBatchFilter
allowAccessToFullInputFormat, batchFinished, input
Methods inherited from class weka.filters.SimpleFilter
setInputFormat
Methods inherited from class weka.filters.Filter
batchFilterFile, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getOutputFormat, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, toString, useFilter, wekaStaticWrapper
-
Constructor Details
-
SubsetByExpression
public SubsetByExpression()
-
-
Method Details
-
globalInfo
Returns a string describing this filter.- Specified by:
globalInfo
in classSimpleFilter
- Returns:
- a description of the filter suitable for displaying in the explorer/experimenter gui
-
mayRemoveInstanceAfterFirstBatchDone
public boolean mayRemoveInstanceAfterFirstBatchDone()SubsetByExpression may return false from input() (thus not making an instance available immediately) even after the first batch has been completed if the user has opted to apply the filter to instances after the first batch (rather than just passing them through).- Overrides:
mayRemoveInstanceAfterFirstBatchDone
in classFilter
- Returns:
- true this filter may remove (consume) input instances after the first batch has been completed.
-
input
Input an instance for filtering. Filter requires all training instances be read before producing output (calling the method batchFinished() makes the data available). If this instance is part of a new batch, m_NewBatch is set to false.- Overrides:
input
in classSimpleBatchFilter
- Parameters:
instance
- the input instance- Returns:
- true if the filtered instance may now be collected with output().
- Throws:
IllegalStateException
- if no input structure has been definedException
- if something goes wrong- See Also:
-
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:-E <expr> The expression to use for filtering (default: true).
-F Apply the filter to instances that arrive after the first (training) batch. The default is to not apply the filter (i.e., always return the instance)
-output-debug-info If set, filter is run in debug mode and may output additional info to the console
-do-not-check-capabilities If set, filter capabilities are not checked when input format is set (use with caution).
- 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
-
getCapabilities
Returns the Capabilities of this filter.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classFilter
- Returns:
- the capabilities of this object
- See Also:
-
setExpression
Sets the expression used for filtering.- Parameters:
value
- the expression
-
getExpression
Returns the expression used for filtering.- Returns:
- the expression
-
expressionTipText
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setFilterAfterFirstBatch
public void setFilterAfterFirstBatch(boolean b) Set whether to apply the filter to instances that arrive once the first (training) batch has been seen. The default is to not apply the filter and just return each instance input. This is so that, when used in the FilteredClassifier, a test instance does not get "consumed" by the filter and a prediction is always generated.- Parameters:
b
- true if the filter should be applied to instances that arrive after the first (training) batch has been processed.
-
getFilterAfterFirstBatch
public boolean getFilterAfterFirstBatch()Get whether to apply the filter to instances that arrive once the first (training) batch has been seen. The default is to not apply the filter and just return each instance input. This is so that, when used in the FilteredClassifier, a test instance does not get "consumed" by the filter and a prediction is always generated.- Returns:
- true if the filter should be applied to instances that arrive after the first (training) batch has been processed.
-
filterAfterFirstBatchTipText
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classFilter
- Returns:
- the revision
-
main
Main method for running this filter.- Parameters:
args
- arguments for the filter: use -h for help
-