Package weka.classifiers

# Class AbstractClassifier

java.lang.Object
weka.classifiers.AbstractClassifier

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Classifier`, `BatchPredictor`, `CapabilitiesHandler`, `CapabilitiesIgnorer`, `CommandlineRunnable`, `OptionHandler`, `RevisionHandler`

Direct Known Subclasses:
  `BayesNet`, `DecisionStump`, `DecisionTable`, `HoeffdingTree`, `IBk`, `J48`, `JRip`, `KStar`, `LinearRegression`, `LMT`, `Logistic`, `LogisticBase`, `M5Base`, `MultilayerPerceptron`, `MultipleClassifiersCombiner`, `NaiveBayes`, `NaiveBayesMultinomial`, `NaiveBayesMultinomialText`, `OneR`, `PART`, `PMMLClassifier`, `PreConstructedLinearModel`, `RandomizableClassifier`, `RandomTree`, `REPTree`, `RuleNode`, `SerializedClassifier`, `SimpleLinearRegression`, `SimpleLogistic`, `SingleClassifierEnhancer`, `SMO`, `SMOreg`, `VotedPerceptron`, `ZeroR`

public abstract class AbstractClassifier extends Object implements Classifier, BatchPredictor, Cloneable, Serializable, OptionHandler, CapabilitiesHandler, RevisionHandler, CapabilitiesIgnorer, CommandlineRunnable
Abstract classifier. All schemes for numeric or nominal prediction in Weka extend this class. Note that a classifier MUST either implement distributionForInstance() or classifyInstance().

Version:
  $Revision: 15520 $
Author:
  Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (trigg@cs.waikato.ac.nz)
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static String`
  `BATCH_SIZE_DEFAULT`
  Default preferred batch size for batch predictions
  `static int`
  `NUM_DECIMAL_PLACES_DEFAULT`
  The number of decimal places used when printing numbers in the model.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractClassifier()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `batchSizeTipText()`
  Returns the tip text for this property
  `double`
  `classifyInstance(Instance instance)`
  Classifies the given test instance.
  `String`
  `debugTipText()`
  Returns the tip text for this property
  `double[]`
  `distributionForInstance(Instance instance)`
  Predicts the class memberships for a given instance.
  `double[][]`
  `distributionsForInstances(Instances batch)`
  Batch prediction method.
  `String`
  `doNotCheckCapabilitiesTipText()`
  Returns the tip text for this property
  `static Classifier`
  `forName(String classifierName, String[] options)`
  Creates a new instance of a classifier given it's class name and (optional) arguments to pass to it's setOptions method.
  `String`
  `getBatchSize()`
  Get the preferred batch size for batch prediction.
  `Capabilities`
  `getCapabilities()`
  Returns the Capabilities of this classifier.
  `boolean`
  `getDebug()`
  Get whether debugging is turned on.
  `boolean`
  `getDoNotCheckCapabilities()`
  Get whether capabilities checking is turned off.
  `int`
  `getNumDecimalPlaces()`
  Get the number of decimal places.
  `String[]`
  `getOptions()`
  Gets the current settings of the Classifier.
  `String`
  `getRevision()`
  Returns the revision string.
  `boolean`
  `implementsMoreEfficientBatchPrediction()`
  Return true if this classifier can generate batch predictions in an efficient manner.
  `Enumeration<Option>`
  `listOptions()`
  Returns an enumeration describing the available options.
  `static Classifier[]`
  `makeCopies(Classifier model, int num)`
  Creates a given number of deep copies of the given classifier using serialization.
  `static Classifier`
  `makeCopy(Classifier model)`
  Creates a deep copy of the given classifier using serialization.
  `String`
  `numDecimalPlacesTipText()`
  Returns the tip text for this property
  `void`
  `postExecution()`
  Perform any teardown stuff that might need to happen after execution.
  `void`
  `preExecution()`
  Perform any setup stuff that might need to happen before commandline execution.
  `void`
  `run(Object toRun, String[] options)`
  Execute the supplied object.
  `static void`
  `runClassifier(Classifier classifier, String[] options)`
  runs the classifier instance with the given options.
  `void`
  `setBatchSize(String size)`
  Set the preferred batch size for batch prediction.
  `void`
  `setDebug(boolean debug)`
  Set debugging mode.
  `void`
  `setDoNotCheckCapabilities(boolean doNotCheckCapabilities)`
  Set whether not to check capabilities.
  `void`
  `setNumDecimalPlaces(int num)`
  Set the number of decimal places.
  `void`
  `setOptions(String[] options)`
  Parses a given list of options.

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

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

  ### Methods inherited from interface weka.classifiers.Classifier

  `buildClassifier`

- ## Field Details

  - ### NUM_DECIMAL_PLACES_DEFAULT

    public static int NUM_DECIMAL_PLACES_DEFAULT
    The number of decimal places used when printing numbers in the model.

  - ### BATCH_SIZE_DEFAULT

    public static String BATCH_SIZE_DEFAULT
    Default preferred batch size for batch predictions

- ## Constructor Details

  - ### AbstractClassifier

    public AbstractClassifier()

- ## Method Details

  - ### forName

    public static Classifier forName(String classifierName, String[] options) throws Exception
    Creates a new instance of a classifier given it's class name and (optional) arguments to pass to it's setOptions method. If the classifier implements OptionHandler and the options parameter is non-null, the classifier will have it's options set.
    Parameters:
      `classifierName` - the fully qualified class name of the classifier
      `options` - an array of options suitable for passing to setOptions. May be null.
    Returns:
      the newly created classifier, ready for use.
    Throws:
      `Exception` - if the classifier name is invalid, or the options supplied are not acceptable to the classifier

  - ### makeCopy

    public static Classifier makeCopy(Classifier model) throws Exception
    Creates a deep copy of the given classifier using serialization.
    Parameters:
      `model` - the classifier to copy
    Returns:
      a deep copy of the classifier
    Throws:
      `Exception` - if an error occurs

  - ### makeCopies

    public static Classifier[] makeCopies(Classifier model, int num) throws Exception
    Creates a given number of deep copies of the given classifier using serialization.
    Parameters:
      `model` - the classifier to copy
      `num` - the number of classifier copies to create.
    Returns:
      an array of classifiers.
    Throws:
      `Exception` - if an error occurs

  - ### runClassifier

    public static void runClassifier(Classifier classifier, String[] options)
    runs the classifier instance with the given options.
    Parameters:
      `classifier` - the classifier to run
      `options` - the commandline options

  - ### classifyInstance

    public double classifyInstance(Instance instance) throws Exception
    Classifies the given test instance. The instance has to belong to a dataset when it's being classified. Note that a classifier MUST implement either this or distributionForInstance().
    Specified by:
      `classifyInstance` in interface `Classifier`
    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:
      `Exception` - if an error occurred during the prediction

  - ### distributionForInstance

    public double[] distributionForInstance(Instance instance) throws Exception
    Predicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero. If the class is numeric, the array must consist of only one element, which contains the predicted value. Note that a classifier MUST implement either this or classifyInstance().
    Specified by:
      `distributionForInstance` in interface `Classifier`
    Parameters:
      `instance` - the instance to be classified
    Returns:
      an array containing the estimated membership probabilities of the test instance in each class or the numeric prediction
    Throws:
      `Exception` - if distribution could not be computed successfully

  - ### listOptions

    public Enumeration<Option> listOptions()
    Returns an enumeration describing the available options.
    Specified by:
      `listOptions` in interface `OptionHandler`
    Returns:
      an enumeration of all the available options.

  - ### getOptions

    public String[] getOptions()
    Gets the current settings of the Classifier.
    Specified by:
      `getOptions` in interface `OptionHandler`
    Returns:
      an array of strings suitable for passing to setOptions

  - ### setOptions

    public void setOptions(String[] options) throws Exception
    Parses a given list of options. Valid options are:

    -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.

    -batch-size
    The desired batch size for batch prediction.

    Specified by:
      `setOptions` in interface `OptionHandler`
    Parameters:
      `options` - the list of options as an array of strings
    Throws:
      `Exception` - if an option is not supported

  - ### getDebug

    public boolean getDebug()
    Get whether debugging is turned on.
    Returns:
      true if debugging output is on

  - ### setDebug

    public void setDebug(boolean debug)
    Set debugging mode.
    Parameters:
      `debug` - true if debug output should be printed

  - ### debugTipText

    public String debugTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getDoNotCheckCapabilities

    public boolean getDoNotCheckCapabilities()
    Get whether capabilities checking is turned off.
    Specified by:
      `getDoNotCheckCapabilities` in interface `CapabilitiesIgnorer`
    Returns:
      true if capabilities checking is turned off.

  - ### setDoNotCheckCapabilities

    public void setDoNotCheckCapabilities(boolean doNotCheckCapabilities)
    Set whether not to check capabilities.
    Specified by:
      `setDoNotCheckCapabilities` in interface `CapabilitiesIgnorer`
    Parameters:
      `doNotCheckCapabilities` - true if capabilities are not to be checked.

  - ### doNotCheckCapabilitiesTipText

    public String doNotCheckCapabilitiesTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### numDecimalPlacesTipText

    public String numDecimalPlacesTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getNumDecimalPlaces

    public int getNumDecimalPlaces()
    Get the number of decimal places.

  - ### setNumDecimalPlaces

    public void setNumDecimalPlaces(int num)
    Set the number of decimal places.

  - ### batchSizeTipText

    public String batchSizeTipText()
    Returns the tip text for this property
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### setBatchSize

    public void setBatchSize(String size)
    Set the preferred batch size for batch prediction.
    Specified by:
      `setBatchSize` in interface `BatchPredictor`
    Parameters:
      `size` - the batch size to use

  - ### getBatchSize

    public String getBatchSize()
    Get the preferred batch size for batch prediction.
    Specified by:
      `getBatchSize` in interface `BatchPredictor`
    Returns:
      the preferred batch size

  - ### implementsMoreEfficientBatchPrediction

    public boolean implementsMoreEfficientBatchPrediction()
    Return true if this classifier can generate batch predictions in an efficient manner. Default implementation here returns false. Subclasses to override as appropriate.
    Specified by:
      `implementsMoreEfficientBatchPrediction` in interface `BatchPredictor`
    Returns:
      true if this classifier can generate batch predictions in an efficient manner.

  - ### distributionsForInstances

    public double[][] distributionsForInstances(Instances batch) throws Exception
    Batch prediction method. This default implementation simply calls distributionForInstance() for each instance in the batch. If subclasses can produce batch predictions in a more efficient manner than this they should override this method and also return true from implementsMoreEfficientBatchPrediction()
    Specified by:
      `distributionsForInstances` in interface `BatchPredictor`
    Parameters:
      `batch` - the instances to get predictions for
    Returns:
      an array of probability distributions, one for each instance in the batch
    Throws:
      `Exception` - if a problem occurs.

  - ### getCapabilities

    public Capabilities getCapabilities()
    Returns the Capabilities of this classifier. Maximally permissive capabilities are allowed by default. Derived classifiers should override this method and first disable all capabilities and then enable just those capabilities that make sense for the scheme.
    Specified by:
      `getCapabilities` in interface `CapabilitiesHandler`
    Specified by:
      `getCapabilities` in interface `Classifier`
    Returns:
      the capabilities of this object
    See Also:
      - `Capabilities`

  - ### getRevision

    public String getRevision()
    Returns the revision string.
    Specified by:
      `getRevision` in interface `RevisionHandler`
    Returns:
      the revision

  - ### preExecution

    public void preExecution() throws Exception
    Perform any setup stuff that might need to happen before commandline execution. Subclasses should override if they need to do something here
    Specified by:
      `preExecution` in interface `CommandlineRunnable`
    Throws:
      `Exception` - if a problem occurs during setup

  - ### run

    public void run(Object toRun, String[] options) throws Exception
    Execute the supplied object.
    Specified by:
      `run` in interface `CommandlineRunnable`
    Parameters:
      `toRun` - the object to execute
      `options` - any options to pass to the object
    Throws:
      `Exception` - if the object is not of the expected type.

  - ### postExecution

    public void postExecution() throws Exception
    Perform any teardown stuff that might need to happen after execution. Subclasses should override if they need to do something here
    Specified by:
      `postExecution` in interface `CommandlineRunnable`
    Throws:
      `Exception` - if a problem occurs during teardown