程序包 weka.filters
类 SimpleBatchFilter
java.lang.Object
weka.filters.Filter
weka.filters.SimpleFilter
weka.filters.SimpleBatchFilter
- 所有已实现的接口:
Serializable
,CapabilitiesHandler
,OptionHandler
,RevisionHandler
- 直接已知子类:
AddClassification
,InterquartileRange
,KernelFilter
,NumericToNominal
,PartitionedMultiFilter
,PLSFilter
,RELAGGS
,SubsetByExpression
,Wavelet
This filter is a superclass for simple batch filters.
General notes:
The following code snippet uses the filter
Only the following abstract methods need to be implemented:
And the getCapabilities() method must return what kind of attributes and classes the filter can handle. If more options are necessary, then the following methods need to be overriden:
Valid filter-specific options are: -D
Turns on output of debugging information.
- After adding instances to the filter via input(Instance) one always has to call batchFinished() to make them available via output().
- After the first call of batchFinished() the field m_FirstBatchDone is
set to
true
.
The following code snippet uses the filter
SomeFilter
on a
dataset that is loaded from filename
.
import weka.core.*; import weka.filters.*; import java.io.*; ... SomeFilter filter = new SomeFilter(); // set necessary options for the filter Instances data = new Instances( new BufferedReader( new FileReader(filename))); Instances filteredData = Filter.useFilter(data, filter);Implementation:
Only the following abstract methods need to be implemented:
- globalInfo()
- determineOutputFormat(Instances)
- process(Instances)
And the getCapabilities() method must return what kind of attributes and classes the filter can handle. If more options are necessary, then the following methods need to be overriden:
- listOptions()
- setOptions(String[])
- getOptions()
public static void main(String[] args) { runFilter(new <Filtername>(), args); }Example implementation:
import weka.core.*; import weka.core.Capabilities.*; import weka.filters.*; public class SimpleBatch extends SimpleBatchFilter { public String globalInfo() { return "A simple batch filter that adds an additional attribute 'bla' at the end containing the index of the processed instance."; } public Capabilities getCapabilities() { Capabilities result = super.getCapabilities(); result.enableAllAttributes(); result.enableAllClasses(); result.enable(Capability.NO_CLASS); // filter doesn't need class to be set return result; } protected Instances determineOutputFormat(Instances inputFormat) { Instances result = new Instances(inputFormat, 0); result.insertAttributeAt(new Attribute("bla"), result.numAttributes()); return result; } protected Instances process(Instances inst) { Instances result = new Instances(determineOutputFormat(inst), 0); for (int i = 0; i < inst.numInstances(); i++) { double[] values = new double[result.numAttributes()]; for (int n = 0; n < inst.numAttributes(); n++) values[n] = inst.instance(i).value(n); values[values.length - 1] = i; result.add(new Instance(1, values)); } return result; } public static void main(String[] args) { runFilter(new SimpleBatch(), args); } }Options:
Valid filter-specific options are: -D
Turns on output of debugging information.
- 版本:
- $Revision: 8954 $
- 作者:
- FracPete (fracpete at waikato dot ac dot nz)
- 另请参阅:
-
SimpleStreamFilter
input(Instance)
batchFinished()
Filter.m_FirstBatchDone
- 序列化表格
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明boolean
Signify that this batch of input to the filter is finished.boolean
Input an instance for filtering.从类继承的方法 weka.filters.SimpleFilter
debugTipText, getDebug, getOptions, globalInfo, listOptions, setDebug, setInputFormat, setOptions
从类继承的方法 weka.filters.Filter
batchFilterFile, filterFile, getCapabilities, getCapabilities, getOutputFormat, getRevision, isFirstBatchDone, isNewBatch, isOutputFormatDefined, main, makeCopies, makeCopy, numPendingOutput, output, outputPeek, toString, useFilter, wekaStaticWrapper
-
构造器详细资料
-
SimpleBatchFilter
public SimpleBatchFilter()
-
-
方法详细资料
-
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.- 覆盖:
input
在类中Filter
- 参数:
instance
- the input instance- 返回:
- true if the filtered instance may now be collected with output().
- 抛出:
IllegalStateException
- if no input structure has been definedException
- if something goes wrong- 另请参阅:
-
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 setInputFormat has been re-assigned or new options have been set). Sets m_FirstBatchDone and m_NewBatch to true.- 覆盖:
batchFinished
在类中Filter
- 返回:
- true if there are instances pending output
- 抛出:
IllegalStateException
- if no input format has been set.Exception
- if something goes wrong- 另请参阅:
-
Filter.m_NewBatch
Filter.m_FirstBatchDone
-