weka.classifiers.meta
Class ClassificationViaClustering

java.lang.Object
  extended by weka.classifiers.Classifier
      extended by weka.classifiers.meta.ClassificationViaClustering
All Implemented Interfaces:
java.io.Serializable, java.lang.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:
Serialized Form

Constructor Summary
ClassificationViaClustering()
          default constructor
 
Method Summary
 void buildClassifier(Instances data)
          builds the classifier
 double classifyInstance(Instance instance)
          Classifies the given test instance.
 java.lang.String clustererTipText()
          Returns the tip text for this property
 Capabilities getCapabilities()
          Returns default capabilities of the classifier.
 Clusterer getClusterer()
          Get the clusterer used as the base learner.
 java.lang.String[] getOptions()
          returns the options of the current setup
 java.lang.String getRevision()
          Returns the revision string.
 java.lang.String globalInfo()
          Returns a string describing classifier
 java.util.Enumeration listOptions()
          Gets an enumeration describing the available options.
static void main(java.lang.String[] args)
          Runs the classifier with the given options
 void setClusterer(Clusterer value)
          Set the base clusterer.
 void setOptions(java.lang.String[] options)
          Parses the options for this object.
 java.lang.String toString()
          Returns a string representation of the classifier.
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getDebug, makeCopies, makeCopy, setDebug
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassificationViaClustering

public ClassificationViaClustering()
default constructor

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 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 java.lang.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(java.lang.String[] options)
                throws java.lang.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:
java.lang.Exception - if setting of options fails

clustererTipText

public java.lang.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 java.lang.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:
java.lang.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:
Capabilities

buildClassifier

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

Specified by:
buildClassifier in class Classifier
Parameters:
data - the training instances
Throws:
java.lang.Exception - if something goes wrong

toString

public java.lang.String toString()
Returns a string representation of the classifier.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the classifier.

getRevision

public java.lang.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(java.lang.String[] args)
Runs the classifier with the given options

Parameters:
args - the commandline options