Class ClassificationViaClustering

java.lang.Object
weka.classifiers.Classifier
weka.classifiers.meta.ClassificationViaClustering
All Implemented Interfaces:
Serializable, Cloneable, CapabilitiesHandler, OptionHandler, RevisionHandler

public class ClassificationViaClustering extends Classifier
A simple meta-classifier that uses a clusterer for classification. For cluster algorithms that use a fixed number of clusterers, like SimpleKMeans, the user has to make sure that the number of clusters to generate are the same as the number of class labels in the dataset in order to obtain a useful model.

Note: at prediction time, a missing value is returned if no cluster is found for the instance.

The code is based on the 'clusters to classes' functionality of the weka.clusterers.ClusterEvaluation class by Mark Hall.

Valid options are:

 -D
  If set, classifier is run in debug mode and
  may output additional info to the console
 -W
  Full name of clusterer.
  (default: weka.clusterers.SimpleKMeans)
 
 Options specific to clusterer weka.clusterers.SimpleKMeans:
 
 -N <num>
  number of clusters.
  (default 2).
 -V
  Display std. deviations for centroids.
 
 -M
  Replace missing values with mean/mode.
 
 -S <num>
  Random number seed.
  (default 10)
Version:
$Revision: 1.5 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Constructor Details

    • ClassificationViaClustering

      public ClassificationViaClustering()
      default constructor
  • Method Details

    • globalInfo

      public String globalInfo()
      Returns a string describing classifier
      Returns:
      a description suitable for displaying in the explorer/experimenter gui
    • listOptions

      public Enumeration listOptions()
      Gets an enumeration describing the available options.
      Specified by:
      listOptions in interface OptionHandler
      Overrides:
      listOptions in class Classifier
      Returns:
      an enumeration of all the available options.
    • getOptions

      public String[] getOptions()
      returns the options of the current setup
      Specified by:
      getOptions in interface OptionHandler
      Overrides:
      getOptions in class Classifier
      Returns:
      the current options
    • setOptions

      public void setOptions(String[] options) throws Exception
      Parses the options for this object.

      Valid options are:

       -D
        If set, classifier is run in debug mode and
        may output additional info to the console
       -W
        Full name of clusterer.
        (default: weka.clusterers.SimpleKMeans)
       
       Options specific to clusterer weka.clusterers.SimpleKMeans:
       
       -N <num>
        number of clusters.
        (default 2).
       -V
        Display std. deviations for centroids.
       
       -M
        Replace missing values with mean/mode.
       
       -S <num>
        Random number seed.
        (default 10)
      Specified by:
      setOptions in interface OptionHandler
      Overrides:
      setOptions in class Classifier
      Parameters:
      options - the options to use
      Throws:
      Exception - if setting of options fails
    • clustererTipText

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

      public void setClusterer(Clusterer value)
      Set the base clusterer.
      Parameters:
      value - the clusterer to use.
    • getClusterer

      public Clusterer getClusterer()
      Get the clusterer used as the base learner.
      Returns:
      the current clusterer
    • classifyInstance

      public double classifyInstance(Instance instance) throws Exception
      Classifies the given test instance.
      Overrides:
      classifyInstance in class Classifier
      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:
      Exception - if an error occurred during the prediction
    • getCapabilities

      public Capabilities getCapabilities()
      Returns default capabilities of the classifier.
      Specified by:
      getCapabilities in interface CapabilitiesHandler
      Overrides:
      getCapabilities in class Classifier
      Returns:
      the capabilities of this classifier
      See Also:
    • buildClassifier

      public void buildClassifier(Instances data) throws Exception
      builds the classifier
      Specified by:
      buildClassifier in class Classifier
      Parameters:
      data - the training instances
      Throws:
      Exception - if something goes wrong
    • toString

      public String toString()
      Returns a string representation of the classifier.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the classifier.
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Overrides:
      getRevision in class Classifier
      Returns:
      the revision
    • main

      public static void main(String[] args)
      Runs the classifier with the given options
      Parameters:
      args - the commandline options