Class Classifier

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, OptionHandler
    Direct Known Subclasses:
    J48, J48WithNDCs, NaiveBayesSimple

    public abstract class Classifier
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable, OptionHandler
    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: 1.11.2.1 $
    Author:
    Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (trigg@cs.waikato.ac.nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Debug

        protected boolean m_Debug
        Whether the classifier is run in debug mode.
      • m_SaAbsent

        protected static boolean m_SaAbsent
      • m_SaRemove

        public static boolean m_SaRemove
    • Constructor Detail

      • Classifier

        public Classifier()
    • Method Detail

      • doDistributionForInstance

        public double[][] doDistributionForInstance​(Instance instance)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • buildClassifier

        public abstract void buildClassifier​(Instances data)
                                      throws java.lang.Exception
        Generates a classifier. Must initialize all fields of the classifier that are not being set via options (ie. multiple calls of buildClassifier must always lead to the same result). Must not change the dataset in any way.
        Parameters:
        data - set of instances serving as training data
        Throws:
        java.lang.Exception - if the classifier has not been generated successfully
      • classifyInstance

        public double classifyInstance​(Instance instance)
                                throws java.lang.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().
        Parameters:
        instance - the instance to be classified
        Returns:
        the predicted most likely class for the instance or Instance.missingValue() if no prediction is made
        Throws:
        java.lang.Exception - if an error occurred during the prediction
      • distributionForInstance

        public double[] distributionForInstance​(Instance instance)
                                         throws java.lang.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().
        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:
        java.lang.Exception - if distribution could not be computed successfully
      • forName

        public static Classifier forName​(java.lang.String classifierName,
                                         java.lang.String[] options)
                                  throws java.lang.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:
        java.lang.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 java.lang.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:
        java.lang.Exception - if an error occurs
      • makeCopies

        public static Classifier[] makeCopies​(Classifier model,
                                              int num)
                                       throws java.lang.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:
        java.lang.Exception - if an error occurs
      • listOptions

        public java.util.Enumeration listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface OptionHandler
        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. Valid options are:

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

        Specified by:
        setOptions in interface OptionHandler
        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
        Returns:
        an array of strings suitable for passing to setOptions
      • setDebug

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

        public void setSaAbsent​(boolean s)
      • getDebug

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

        public boolean getSaAbsent()
      • debugTipText

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

        public java.lang.String saAbsentTipText()