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 voidbuildClassifier(Instances data)builds the classifierdoubleclassifyInstance(Instance instance)Classifies the given test instance.java.lang.StringclustererTipText()Returns the tip text for this propertyCapabilitiesgetCapabilities()Returns default capabilities of the classifier.ClusterergetClusterer()Get the clusterer used as the base learner.java.lang.String[]getOptions()returns the options of the current setupjava.lang.StringgetRevision()Returns the revision string.java.lang.StringglobalInfo()Returns a string describing classifierjava.util.EnumerationlistOptions()Gets an enumeration describing the available options.static voidmain(java.lang.String[] args)Runs the classifier with the given optionsvoidsetClusterer(Clusterer value)Set the base clusterer.voidsetOptions(java.lang.String[] options)Parses the options for this object.java.lang.StringtoString()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:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classClassifier- Returns:
- an enumeration of all the available options.
-
getOptions
public java.lang.String[] getOptions()
returns the options of the current setup- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classClassifier- Returns:
- the current options
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses 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:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin 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:
classifyInstancein 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:
getCapabilitiesin interfaceCapabilitiesHandler- Overrides:
getCapabilitiesin 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:
buildClassifierin 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:
toStringin classjava.lang.Object- Returns:
- a string representation of the classifier.
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin 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
-
-