Package weka.classifiers.meta
Class ClassificationViaClustering
- java.lang.Object
-
- weka.classifiers.Classifier
-
- 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
Constructors Constructor Description ClassificationViaClustering()
default constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildClassifier(Instances data)
builds the classifierdouble
classifyInstance(Instance instance)
Classifies the given test instance.java.lang.String
clustererTipText()
Returns the tip text for this propertyCapabilities
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 setupjava.lang.String
getRevision()
Returns the revision string.java.lang.String
globalInfo()
Returns a string describing classifierjava.util.Enumeration
listOptions()
Gets an enumeration describing the available options.static void
main(java.lang.String[] args)
Runs the classifier with the given optionsvoid
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
-
-
-
-
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 interfaceOptionHandler
- Overrides:
listOptions
in classClassifier
- 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 interfaceOptionHandler
- Overrides:
getOptions
in classClassifier
- 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 interfaceOptionHandler
- Overrides:
setOptions
in classClassifier
- 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 classClassifier
- 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 interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classClassifier
- 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 classClassifier
- 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 classjava.lang.Object
- Returns:
- a string representation of the classifier.
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classClassifier
- Returns:
- the revision
-
main
public static void main(java.lang.String[] args)
Runs the classifier with the given options- Parameters:
args
- the commandline options
-
-