weka.classifiers.meta

## Class WeightedInstancesHandlerWrapper

- java.lang.Object
- - weka.classifiers.AbstractClassifier
  - - weka.classifiers.SingleClassifierEnhancer
    - - weka.classifiers.RandomizableSingleClassifierEnhancer
      - - weka.classifiers.meta.WeightedInstancesHandlerWrapper

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, BatchPredictor, CapabilitiesHandler, CapabilitiesIgnorer, CommandlineRunnable, OptionHandler, Randomizable, RevisionHandler, WeightedInstancesHandler

      public class WeightedInstancesHandlerWrapper
      extends RandomizableSingleClassifierEnhancer
      implements WeightedInstancesHandler

  Generic wrapper around any classifier to enable weighted instances support.
  Uses resampling with weights if the base classifier is not implementing the weka.core.WeightedInstancesHandler interface and there are instance weights other 1.0 present. By default, the training data is passed through to the base classifier if it can handle instance weights. However, it is possible to force the use of resampling with weights as well.
  Valid options are:

       -force-resample-with-weights
        Forces resampling of weights, regardless of whether
        base classifier handles instance weights

       -S <num>
        Random number seed.
        (default 1)

       -W
        Full name of base classifier.
        (default: weka.classifiers.rules.ZeroR)

       -output-debug-info
        If set, classifier is run in debug mode and
        may output additional info to the console

       -do-not-check-capabilities
        If set, classifier capabilities are not checked before classifier is built
        (use with caution).

       -num-decimal-places
        The number of decimal places for the output of numbers in the model (default 2).

       Options specific to classifier weka.classifiers.rules.ZeroR:

       -output-debug-info
        If set, classifier is run in debug mode and
        may output additional info to the console

       -do-not-check-capabilities
        If set, classifier capabilities are not checked before classifier is built
        (use with caution).

       -num-decimal-places
        The number of decimal places for the output of numbers in the model (default 2).

  Version:
    $Revision: 12226 $
  Author:
    FracPete (fracpete at waikato dot ac dot nz)
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `FORCE_RESAMPLE_WITH_WEIGHTS` command-line option for resampling with weights.

    - ### Fields inherited from class weka.classifiers.AbstractClassifier

      `BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WeightedInstancesHandlerWrapper()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `buildClassifier(Instances data)` builds the classifier.
    `double` | `classifyInstance(Instance instance)` Classifies the given test instance.
    `double[]` | `distributionForInstance(Instance instance)` Calculates the class membership probabilities for the given test instance.
    `java.lang.String` | `forceResampleWithWeightsTipText()` Returns the tip text for this property
    `boolean` | `getForceResampleWithWeights()` Gets the size of each subSpace, as a percentage of the training set size.
    `java.lang.String[]` | `getOptions()` Gets the current settings of the Classifier.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `java.lang.String` | `globalInfo()` Returns a string describing classifier
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `static void` | `main(java.lang.String[] args)` Main method for testing this class.
    `void` | `setForceResampleWithWeights(boolean value)` Sets the size of each subSpace, as a percentage of the training set size.
    `void` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `java.lang.String` | `toString()` Returns a string description of the model.

    - ### Methods inherited from class weka.classifiers.RandomizableSingleClassifierEnhancer

      `getSeed, seedTipText, setSeed`

    - ### Methods inherited from class weka.classifiers.SingleClassifierEnhancer

      `classifierTipText, getCapabilities, getClassifier, postExecution, preExecution, setClassifier`

    - ### Methods inherited from class weka.classifiers.AbstractClassifier

      `batchSizeTipText, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### FORCE_RESAMPLE_WITH_WEIGHTS

          public static final java.lang.String FORCE_RESAMPLE_WITH_WEIGHTS

      command-line option for resampling with weights.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### WeightedInstancesHandlerWrapper

          public WeightedInstancesHandlerWrapper()

  - ### Method Detail

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing classifier
      Returns:
        a description suitable for displaying in the explorer/experimenter gui

    - #### listOptions

          public java.util.Enumeration<Option> listOptions()

      Returns an enumeration describing the available options.
      Specified by:
        `listOptions` in interface `OptionHandler`
      Overrides:
        `listOptions` in class `RandomizableSingleClassifierEnhancer`
      Returns:
        an enumeration of all the available options.

    - #### setOptions

          public void setOptions(java.lang.String[] options)
                          throws java.lang.Exception

      Parses a given list of options.
      Specified by:
        `setOptions` in interface `OptionHandler`
      Overrides:
        `setOptions` in class `RandomizableSingleClassifierEnhancer`
      Parameters:
        `options` - the list of options as an array of strings
      Throws:
        `java.lang.Exception` - if an option is not supported

    - #### getOptions

          public java.lang.String[] getOptions()

      Gets the current settings of the Classifier.
      Specified by:
        `getOptions` in interface `OptionHandler`
      Overrides:
        `getOptions` in class `RandomizableSingleClassifierEnhancer`
      Returns:
        an array of strings suitable for passing to setOptions

    - #### getForceResampleWithWeights

          public boolean getForceResampleWithWeights()

      Gets the size of each subSpace, as a percentage of the training set size.
      Returns:
        the subSpace size, as a percentage.

    - #### setForceResampleWithWeights

          public void setForceResampleWithWeights(boolean value)

      Sets the size of each subSpace, as a percentage of the training set size.
      Parameters:
        `value` - the subSpace size, as a percentage.

    - #### forceResampleWithWeightsTipText

          public java.lang.String forceResampleWithWeightsTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### buildClassifier

          public void buildClassifier(Instances data)
                               throws java.lang.Exception

      builds the classifier.
      Specified by:
        `buildClassifier` in interface `Classifier`
      Parameters:
        `data` - the training data to be used for generating the classifier.
      Throws:
        `java.lang.Exception` - if the classifier could not be built successfully

    - #### distributionForInstance

          public double[] distributionForInstance(Instance instance)
                                           throws java.lang.Exception

      Calculates the class membership probabilities for the given test instance.
      Specified by:
        `distributionForInstance` in interface `Classifier`
      Overrides:
        `distributionForInstance` in class `AbstractClassifier`
      Parameters:
        `instance` - the instance to be classified
      Returns:
        preedicted class probability distribution
      Throws:
        `java.lang.Exception` - if distribution can't be computed successfully

    - #### classifyInstance

          public double classifyInstance(Instance instance)
                                  throws java.lang.Exception

      Classifies the given test instance.
      Specified by:
        `classifyInstance` in interface `Classifier`
      Overrides:
        `classifyInstance` in class `AbstractClassifier`
      Parameters:
        `instance` - the instance to be classified
      Returns:
        the predicted most likely class for the instance or Utils.missingValue() if no prediction is made
      Throws:
        `java.lang.Exception` - if an error occurred during the prediction

    - #### toString

          public java.lang.String toString()

      Returns a string description of the model.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the model

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Overrides:
        `getRevision` in class `AbstractClassifier`
      Returns:
        the revision

    - #### main

          public static void main(java.lang.String[] args)

      Main method for testing this class.
      Parameters:
        `args` - the options