weka.classifiers
Class Classifier

java.lang.Object
  extended by weka.classifiers.Classifier
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DistributionClassifier

public abstract class Classifier
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Abstract classifier. All schemes for numeric or nominal prediction in Weka extend this class.

Version:
$Revision: 1.1 $
Author:
Eibe Frank ([email protected]), Len Trigg ([email protected])
See Also:
Serialized Form

Constructor Summary
Classifier()
           
 
Method Summary
abstract  void buildClassifier(Instances data)
          Generates a classifier.
abstract  double classifyInstance(Instance instance)
          Classifies a given instance.
static Classifier forName(java.lang.String classifierName, java.lang.String[] options)
          Creates a new instance of a classifier given it's class name and (optional) arguments to pass to it's setOptions method.
static Classifier[] makeCopies(Classifier model, int num)
          Creates copies of the current classifier, which can then be used for boosting etc.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Classifier

public Classifier()
Method Detail

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 abstract double classifyInstance(Instance instance)
                                 throws java.lang.Exception
Classifies a given instance.

Parameters:
instance - the instance to be classified
Returns:
index of the predicted class as a double if the class is nominal, otherwise the predicted value
Throws:
java.lang.Exception - if instance could not be classified 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

makeCopies

public static Classifier[] makeCopies(Classifier model,
                                      int num)
                               throws java.lang.Exception
Creates copies of the current classifier, which can then be used for boosting etc. Note that this method now uses Serialization to perform a deep copy, so the Classifier object must be fully Serializable. Any currently built model will now be copied as well.

Parameters:
model - an example classifier to copy
num - the number of classifiers copies to create.
Returns:
an array of classifiers.
Throws:
java.lang.Exception - if an error occurs