Class 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 boolean m_CanAbstain
      whether the base classifier can abstain.
      protected weka.filters.unsupervised.attribute.Remove m_Remove
      The additional remove filter.
      protected boolean m_Stopped
      whether the classifier was stopped.
      • Fields inherited from class weka.classifiers.meta.FilteredClassifier

        m_DoNotCheckForModifiedClassAttribute, m_Filter, m_FilteredInstances, m_ReorderFiltered, m_ReorderOriginal
      • Fields inherited from class weka.classifiers.RandomizableSingleClassifierEnhancer

        m_Seed
      • Fields inherited from class weka.classifiers.SingleClassifierEnhancer

        m_Classifier
      • Fields inherited from class weka.classifiers.AbstractClassifier

        BATCH_SIZE_DEFAULT, m_BatchSize, m_Debug, m_DoNotCheckCapabilities, m_numDecimalPlaces, NUM_DECIMAL_PLACES_DEFAULT
      • Fields inherited from interface weka.core.Drawable

        BayesNet, Newick, NOT_DRAWABLE, TREE
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildClassifier​(weka.core.Instances data)
      Build the classifier on the filtered data.
      boolean canAbstain()
      Whether abstaining is possible, e.g., used in meta-classifiers.
      double classifyInstance​(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.Instance filter​(weka.core.Instance instance)
      Filters the Instance through the remove filter if necessary.
      protected weka.core.Instances filter​(weka.core.Instances data)
      Filters the dataset through the remove filter if necessary.
      protected weka.core.Instance filter​(weka.filters.Filter filter, weka.core.Instance instance)
      Filters the Instance through the specified filter.
      double getAbstentionClassification​(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.Capabilities getCapabilities()
      Returns default capabilities of the classifier.
      String[] getOptions()
      Gets the current settings of the Classifier.
      String getRemoveAttributeIndices()
      Returns the attributes indices that are removed before applying the actual filter.
      String getRevision()
      Returns the revision string.
      String globalInfo()
      Returns a string describing this classifier.
      protected boolean isRemoveUsed()
      Returns whether the Remove filter is used at all.
      boolean isStopped()
      Whether the execution has been stopped.
      Enumeration listOptions()
      Returns an enumeration describing the available options.
      static void main​(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.
      String removeAttributeIndicesTipText()
      Returns the tip text for this property.
      void setOptions​(String[] options)
      Parses a given list of options.
      void setRemoveAttributeIndices​(String value)
      Sets the attribute indices to remove before applying the actual filter.
      void stopExecution()
      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
    • Field Detail

      • m_Remove

        protected weka.filters.unsupervised.attribute.Remove m_Remove
        The additional remove filter.
      • m_CanAbstain

        protected boolean m_CanAbstain
        whether the base classifier can abstain.
      • m_Stopped

        protected boolean m_Stopped
        whether the classifier was stopped.
    • Constructor Detail

      • FilteredClassifierExt

        public FilteredClassifierExt()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this classifier.
        Overrides:
        globalInfo in class weka.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:
        listOptions in interface weka.core.OptionHandler
        Overrides:
        listOptions in class weka.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:
        setOptions in interface weka.core.OptionHandler
        Overrides:
        setOptions in class weka.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:
        getOptions in interface weka.core.OptionHandler
        Overrides:
        getOptions in class weka.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:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Specified by:
        getCapabilities in interface weka.classifiers.Classifier
        Overrides:
        getCapabilities in class weka.classifiers.meta.FilteredClassifier
        Returns:
        the capabilities of this classifier
      • filter

        protected weka.core.Instances filter​(weka.core.Instances data)
                                      throws Exception
        Filters the dataset through the remove filter if necessary.
        Parameters:
        data - the data to filter
        Returns:
        the processed data
        Throws:
        Exception - if filtering fails
        See Also:
        m_Remove
      • buildClassifier

        public void buildClassifier​(weka.core.Instances data)
                             throws Exception
        Build the classifier on the filtered data.
        Specified by:
        buildClassifier in interface weka.classifiers.Classifier
        Overrides:
        buildClassifier in class weka.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 Exception
        Filters the Instance through the specified filter.
        Parameters:
        filter - the filter to use
        instance - the instance to filter
        Returns:
        the processed instance
        Throws:
        Exception - if filtering fails
      • filter

        protected weka.core.Instance filter​(weka.core.Instance instance)
                                     throws Exception
        Filters the Instance through the remove filter if necessary.
        Parameters:
        instance - the instance to filter
        Returns:
        the processed instance
        Throws:
        Exception - if filtering fails
        See Also:
        m_Remove
      • classifyInstance

        public double classifyInstance​(weka.core.Instance instance)
                                throws Exception
        Simply synchronized call of inherited method.
        Specified by:
        classifyInstance in interface weka.classifiers.Classifier
        Overrides:
        classifyInstance in class weka.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 Exception
        Classifies a given instance after filtering.
        Specified by:
        distributionForInstance in interface weka.classifiers.Classifier
        Overrides:
        distributionForInstance in class weka.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 Exception
        Batch scoring method. Calls the appropriate method for the base learner if it implements BatchPredictor. Otherwise it simply calls the distributionForInstance() method repeatedly.
        Specified by:
        distributionsForInstances in interface weka.core.BatchPredictor
        Overrides:
        distributionsForInstances in class weka.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 Exception
        Returns 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:
        predictIntervals in interface weka.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:
        canAbstain in interface AbstainingClassifier
        Returns:
        true if abstaining is possible
      • getAbstentionClassification

        public double getAbstentionClassification​(weka.core.Instance inst)
                                           throws Exception
        The prediction that made the classifier abstain.
        Specified by:
        getAbstentionClassification in interface AbstainingClassifier
        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 Exception
        The class distribution that made the classifier abstain.
        Specified by:
        getAbstentionDistribution in interface AbstainingClassifier
        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:
        stopExecution in interface Stoppable
      • isStopped

        public boolean isStopped()
        Whether the execution has been stopped.
        Specified by:
        isStopped in interface StoppableWithFeedback
        Returns:
        true if stopped
      • getRevision

        public String getRevision()
        Returns the revision string.
        Specified by:
        getRevision in interface weka.core.RevisionHandler
        Overrides:
        getRevision in class weka.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