Package weka.classifiers.meta
Class FilteredClassifierExt
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.SingleClassifierEnhancer
-
- weka.classifiers.RandomizableSingleClassifierEnhancer
-
- weka.classifiers.meta.FilteredClassifier
-
- weka.classifiers.meta.FilteredClassifierExt
-
- All Implemented Interfaces:
Stoppable,StoppableWithFeedback,Serializable,Cloneable,AbstainingClassifier,weka.classifiers.Classifier,weka.classifiers.IntervalEstimator,weka.classifiers.IterativeClassifier,ThreadSafeClassifier,weka.core.BatchPredictor,weka.core.CapabilitiesHandler,weka.core.CapabilitiesIgnorer,weka.core.CommandlineRunnable,weka.core.Drawable,weka.core.OptionHandler,weka.core.PartitionGenerator,weka.core.Randomizable,weka.core.RevisionHandler,weka.core.WeightedAttributesHandler,weka.core.WeightedInstancesHandler
public class FilteredClassifierExt extends weka.classifiers.meta.FilteredClassifier implements weka.core.WeightedInstancesHandler, weka.classifiers.IntervalEstimator, AbstainingClassifier, ThreadSafeClassifier, StoppableWithFeedback
Class for running an arbitrary classifier on data that has been passed through an arbitrary filter. Like the classifier, the structure of the filter is based exclusively on the training data and test instances will be processed by the filter without changing their structure.
In addition to the default FilteredClassifier, one can specify a range of attributes that are to be removed before applying the actual filter. Useful to remove ID attributes, without having to nest another FilteredClassifier.
The meta-classifier also 'pretends' to be able to:
- handle weighted instances
- produce confidence intervals
This will only lead to reasonable results, of course, if the base classifier supports this functionality.
Valid options are:
-R <att list> The range of attributes to remove. 'first' and 'last' are accepted as well. (default: none)
-F <filter specification> Full class name of filter to use, followed by filter options. eg: "weka.filters.unsupervised.attribute.Remove -V -R 1,2"
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.trees.J48)
Options specific to classifier weka.classifiers.trees.J48:
-U Use unpruned tree.
-O Do not collapse tree.
-C <pruning confidence> Set confidence threshold for pruning. (default 0.25)
-M <minimum number of instances> Set minimum number of instances per leaf. (default 2)
-R Use reduced error pruning.
-N <number of folds> Set number of folds for reduced error pruning. One fold is used as pruning set. (default 3)
-B Use binary splits only.
-S Don't perform subtree raising.
-L Do not clean up after the tree has been built.
-A Laplace smoothing for predicted probabilities.
-J Do not use MDL correction for info gain on numeric attributes.
-Q <seed> Seed for random data shuffling (default 1).
- Version:
- $Revision$
- Author:
- Len Trigg ([email protected]), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_CanAbstainwhether the base classifier can abstain.protected weka.filters.unsupervised.attribute.Removem_RemoveThe additional remove filter.protected booleanm_Stoppedwhether the classifier was stopped.-
Fields inherited from class weka.classifiers.meta.FilteredClassifier
m_DoNotCheckForModifiedClassAttribute, m_Filter, m_FilteredInstances, m_ReorderFiltered, m_ReorderOriginal
-
-
Constructor Summary
Constructors Constructor Description FilteredClassifierExt()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(weka.core.Instances data)Build the classifier on the filtered data.booleancanAbstain()Whether abstaining is possible, e.g., used in meta-classifiers.doubleclassifyInstance(weka.core.Instance instance)Simply synchronized call of inherited method.double[]distributionForInstance(weka.core.Instance instance)Classifies a given instance after filtering.double[][]distributionsForInstances(weka.core.Instances insts)Batch scoring method.protected weka.core.Instancefilter(weka.core.Instance instance)Filters the Instance through the remove filter if necessary.protected weka.core.Instancesfilter(weka.core.Instances data)Filters the dataset through the remove filter if necessary.protected weka.core.Instancefilter(weka.filters.Filter filter, weka.core.Instance instance)Filters the Instance through the specified filter.doublegetAbstentionClassification(weka.core.Instance inst)The prediction that made the classifier abstain.double[]getAbstentionDistribution(weka.core.Instance inst)The class distribution that made the classifier abstain.weka.core.CapabilitiesgetCapabilities()Returns default capabilities of the classifier.String[]getOptions()Gets the current settings of the Classifier.StringgetRemoveAttributeIndices()Returns the attributes indices that are removed before applying the actual filter.StringgetRevision()Returns the revision string.StringglobalInfo()Returns a string describing this classifier.protected booleanisRemoveUsed()Returns whether the Remove filter is used at all.booleanisStopped()Whether the execution has been stopped.EnumerationlistOptions()Returns an enumeration describing the available options.static voidmain(String[] args)Main method for running this classifier.double[][]predictIntervals(weka.core.Instance instance, double confidenceLevel)Returns an N * 2 array, where N is the number of prediction intervals.StringremoveAttributeIndicesTipText()Returns the tip text for this property.voidsetOptions(String[] options)Parses a given list of options.voidsetRemoveAttributeIndices(String value)Sets the attribute indices to remove before applying the actual filter.voidstopExecution()Stops the execution.-
Methods inherited from class weka.classifiers.meta.FilteredClassifier
batchSizeTipText, defaultClassifierString, defaultFilterString, done, doNotCheckForModifiedClassAttributeTipText, filterInstance, filterTipText, generatePartition, getBatchSize, getDoNotCheckForModifiedClassAttribute, getFilter, getFilterSpec, getMembershipValues, getResume, graph, graphType, implementsMoreEfficientBatchPrediction, initializeClassifier, next, numElements, resampleAttributes, resumeTipText, setBatchSize, setDoNotCheckForModifiedClassAttribute, setFilter, setResume, setUp, toString
-
Methods inherited from class weka.classifiers.RandomizableSingleClassifierEnhancer
getSeed, seedTipText, setSeed
-
Methods inherited from class weka.classifiers.SingleClassifierEnhancer
classifierTipText, defaultClassifierOptions, getClassifier, getClassifierSpec, postExecution, preExecution, setClassifier
-
Methods inherited from class weka.classifiers.AbstractClassifier
debugTipText, doNotCheckCapabilitiesTipText, forName, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
-
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing this classifier.- Overrides:
globalInfoin classweka.classifiers.meta.FilteredClassifier- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
listOptions
public Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceweka.core.OptionHandler- Overrides:
listOptionsin classweka.classifiers.meta.FilteredClassifier- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(String[] options) throws Exception
Parses a given list of options.
Valid options are:
-R <att list> The range of attributes to remove. 'first' and 'last' are accepted as well. (default: none)
-F <filter specification> Full class name of filter to use, followed by filter options. eg: "weka.filters.unsupervised.attribute.Remove -V -R 1,2"
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.trees.J48)
Options specific to classifier weka.classifiers.trees.J48:
-U Use unpruned tree.
-O Do not collapse tree.
-C <pruning confidence> Set confidence threshold for pruning. (default 0.25)
-M <minimum number of instances> Set minimum number of instances per leaf. (default 2)
-R Use reduced error pruning.
-N <number of folds> Set number of folds for reduced error pruning. One fold is used as pruning set. (default 3)
-B Use binary splits only.
-S Don't perform subtree raising.
-L Do not clean up after the tree has been built.
-A Laplace smoothing for predicted probabilities.
-J Do not use MDL correction for info gain on numeric attributes.
-Q <seed> Seed for random data shuffling (default 1).
- Specified by:
setOptionsin interfaceweka.core.OptionHandler- Overrides:
setOptionsin classweka.classifiers.meta.FilteredClassifier- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
getOptions
public String[] getOptions()
Gets the current settings of the Classifier.- Specified by:
getOptionsin interfaceweka.core.OptionHandler- Overrides:
getOptionsin classweka.classifiers.meta.FilteredClassifier- Returns:
- an array of strings suitable for passing to setOptions
-
removeAttributeIndicesTipText
public String removeAttributeIndicesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setRemoveAttributeIndices
public void setRemoveAttributeIndices(String value)
Sets the attribute indices to remove before applying the actual filter.- Parameters:
value- the attribute indices (1-based)
-
getRemoveAttributeIndices
public String getRemoveAttributeIndices()
Returns the attributes indices that are removed before applying the actual filter.- Returns:
- the attribute indices (1-based)
-
isRemoveUsed
protected boolean isRemoveUsed()
Returns whether the Remove filter is used at all.- Returns:
- true if the Remove filter is used
-
getCapabilities
public weka.core.Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceweka.core.CapabilitiesHandler- Specified by:
getCapabilitiesin interfaceweka.classifiers.Classifier- Overrides:
getCapabilitiesin classweka.classifiers.meta.FilteredClassifier- Returns:
- the capabilities of this classifier
-
filter
protected weka.core.Instances filter(weka.core.Instances data) throws ExceptionFilters the dataset through the remove filter if necessary.
-
buildClassifier
public void buildClassifier(weka.core.Instances data) throws ExceptionBuild the classifier on the filtered data.- Specified by:
buildClassifierin interfaceweka.classifiers.Classifier- Overrides:
buildClassifierin classweka.classifiers.meta.FilteredClassifier- Parameters:
data- the training data- Throws:
Exception- if the classifier could not be built successfully
-
filter
protected weka.core.Instance filter(weka.filters.Filter filter, weka.core.Instance instance) throws ExceptionFilters the Instance through the specified filter.- Parameters:
filter- the filter to useinstance- the instance to filter- Returns:
- the processed instance
- Throws:
Exception- if filtering fails
-
filter
protected weka.core.Instance filter(weka.core.Instance instance) throws ExceptionFilters the Instance through the remove filter if necessary.
-
classifyInstance
public double classifyInstance(weka.core.Instance instance) throws ExceptionSimply synchronized call of inherited method.- Specified by:
classifyInstancein interfaceweka.classifiers.Classifier- Overrides:
classifyInstancein classweka.classifiers.AbstractClassifier- Parameters:
instance- the instance to classify- Returns:
- the classification
- Throws:
Exception- if failed to make prediction
-
distributionForInstance
public double[] distributionForInstance(weka.core.Instance instance) throws ExceptionClassifies a given instance after filtering.- Specified by:
distributionForInstancein interfaceweka.classifiers.Classifier- Overrides:
distributionForInstancein classweka.classifiers.meta.FilteredClassifier- Parameters:
instance- the instance to be classified- Returns:
- the class distribution for the given instance
- Throws:
Exception- if instance could not be classified successfully
-
distributionsForInstances
public double[][] distributionsForInstances(weka.core.Instances insts) throws ExceptionBatch scoring method. Calls the appropriate method for the base learner if it implements BatchPredictor. Otherwise it simply calls the distributionForInstance() method repeatedly.- Specified by:
distributionsForInstancesin interfaceweka.core.BatchPredictor- Overrides:
distributionsForInstancesin classweka.classifiers.meta.FilteredClassifier- Parameters:
insts- the instances to get predictions for- Returns:
- an array of probability distributions, one for each instance
- Throws:
Exception- if a problem occurs
-
predictIntervals
public double[][] predictIntervals(weka.core.Instance instance, double confidenceLevel) throws ExceptionReturns an N * 2 array, where N is the number of prediction intervals. In each row, the first element contains the lower boundary of the corresponding prediction interval and the second element the upper boundary.- Specified by:
predictIntervalsin interfaceweka.classifiers.IntervalEstimator- Parameters:
instance- the instance to make the prediction for.confidenceLevel- the percentage of cases that the interval should cover.- Returns:
- an array of prediction intervals
- Throws:
Exception- if the intervals can't be computed
-
canAbstain
public boolean canAbstain()
Whether abstaining is possible, e.g., used in meta-classifiers.- Specified by:
canAbstainin interfaceAbstainingClassifier- Returns:
- true if abstaining is possible
-
getAbstentionClassification
public double getAbstentionClassification(weka.core.Instance inst) throws ExceptionThe prediction that made the classifier abstain.- Specified by:
getAbstentionClassificationin interfaceAbstainingClassifier- Parameters:
inst- the instance to get the prediction for- Returns:
- the prediction,
Utils.missingValue()if abstaining is not possible - Throws:
Exception- if fails to make prediction
-
getAbstentionDistribution
public double[] getAbstentionDistribution(weka.core.Instance inst) throws ExceptionThe class distribution that made the classifier abstain.- Specified by:
getAbstentionDistributionin interfaceAbstainingClassifier- Parameters:
inst- the instance to get the prediction for- Returns:
- the class distribution, null if abstaining is not possible
- Throws:
Exception- if fails to make prediction
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceStoppable
-
isStopped
public boolean isStopped()
Whether the execution has been stopped.- Specified by:
isStoppedin interfaceStoppableWithFeedback- Returns:
- true if stopped
-
getRevision
public String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceweka.core.RevisionHandler- Overrides:
getRevisionin classweka.classifiers.meta.FilteredClassifier- Returns:
- the revision
-
main
public static void main(String[] args)
Main method for running this classifier.- Parameters:
args- the parameters, use -h to display them
-
-