Package weka.clusterers
Class HierarchicalClusterer
- java.lang.Object
-
- weka.clusterers.AbstractClusterer
-
- weka.clusterers.HierarchicalClusterer
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Clusterer,CapabilitiesHandler,Drawable,OptionHandler,RevisionHandler
public class HierarchicalClusterer extends AbstractClusterer implements OptionHandler, CapabilitiesHandler, Drawable
Hierarchical clustering class. Implements a number of classic hierarchical clustering methods. Valid options are:-N number of clusters
-L Link type (Single, Complete, Average, Mean, Centroid, Ward, Adjusted complete, Neighbor Joining) [SINGLE|COMPLETE|AVERAGE|MEAN|CENTROID|WARD|ADJCOMLPETE|NEIGHBOR_JOINING]
-A Distance function to use. (default: weka.core.EuclideanDistance)
-P Print hierarchy in Newick format, which can be used for display in other programs.
-D If set, classifier is run in debug mode and may output additional info to the console.
-B \If set, distance is interpreted as branch length, otherwise it is node height.
- Version:
- $Revision: 11330 $
- Author:
- Remco Bouckaert (rrb@xm.co.nz, remco@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Tag[]TAGS_LINK_TYPE-
Fields inherited from interface weka.core.Drawable
BayesNet, Newick, NOT_DRAWABLE, TREE
-
-
Constructor Summary
Constructors Constructor Description HierarchicalClusterer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClusterer(Instances data)Generates a clusterer.intclusterInstance(Instance instance)Classifies a given instance.java.lang.StringdebugTipText()Returns the tip text for this propertyjava.lang.StringdistanceFunctionTipText()java.lang.StringdistanceIsBranchLengthTipText()double[]distributionForInstance(Instance instance)Predicts the cluster memberships for a given instance.CapabilitiesgetCapabilities()Returns the Capabilities of this clusterer.booleangetDebug()Get whether debugging is turned on.DistanceFunctiongetDistanceFunction()booleangetDistanceIsBranchLength()SelectedTaggetLinkType()intgetNumClusters()java.lang.String[]getOptions()Gets the current settings of the clusterer.booleangetPrintNewick()java.lang.StringgetRevision()Returns the revision string.java.lang.StringglobalInfo()This will return a string describing the clusterer.java.lang.Stringgraph()Returns a string that describes a graph representing the object.intgraphType()Returns the type of graph representing the object.java.lang.StringlinkTypeTipText()java.util.EnumerationlistOptions()Returns an enumeration describing the available options.static voidmain(java.lang.String[] argv)intnumberOfClusters()Returns the number of clusters.java.lang.StringnumClustersTipText()java.lang.StringprintNewickTipText()voidsetDebug(boolean debug)Set debugging mode.voidsetDistanceFunction(DistanceFunction distanceFunction)voidsetDistanceIsBranchLength(boolean bDistanceIsHeight)voidsetLinkType(SelectedTag newLinkType)voidsetNumClusters(int nClusters)voidsetOptions(java.lang.String[] options)Parses a given list of options.voidsetPrintNewick(boolean bPrintNewick)java.lang.StringtoString()-
Methods inherited from class weka.clusterers.AbstractClusterer
forName, makeCopies, makeCopy
-
-
-
-
Field Detail
-
TAGS_LINK_TYPE
public static final Tag[] TAGS_LINK_TYPE
-
-
Method Detail
-
setNumClusters
public void setNumClusters(int nClusters)
-
getNumClusters
public int getNumClusters()
-
getDistanceFunction
public DistanceFunction getDistanceFunction()
-
setDistanceFunction
public void setDistanceFunction(DistanceFunction distanceFunction)
-
getPrintNewick
public boolean getPrintNewick()
-
setPrintNewick
public void setPrintNewick(boolean bPrintNewick)
-
setLinkType
public void setLinkType(SelectedTag newLinkType)
-
getLinkType
public SelectedTag getLinkType()
-
buildClusterer
public void buildClusterer(Instances data) throws java.lang.Exception
Description copied from class:AbstractClustererGenerates a clusterer. Has to initialize all fields of the clusterer that are not being set via options.- Specified by:
buildClustererin interfaceClusterer- Specified by:
buildClustererin classAbstractClusterer- Parameters:
data- set of instances serving as training data- Throws:
java.lang.Exception- if the clusterer has not been generated successfully
-
clusterInstance
public int clusterInstance(Instance instance) throws java.lang.Exception
Description copied from class:AbstractClustererClassifies a given instance. Either this or distributionForInstance() needs to be implemented by subclasses.- Specified by:
clusterInstancein interfaceClusterer- Overrides:
clusterInstancein classAbstractClusterer- Parameters:
instance- the instance to be assigned to a cluster- Returns:
- the number of the assigned cluster as an integer
- Throws:
java.lang.Exception- if instance could not be clustered successfully
-
distributionForInstance
public double[] distributionForInstance(Instance instance) throws java.lang.Exception
Description copied from class:AbstractClustererPredicts the cluster memberships for a given instance. Either this or clusterInstance() needs to be implemented by subclasses.- Specified by:
distributionForInstancein interfaceClusterer- Overrides:
distributionForInstancein classAbstractClusterer- Parameters:
instance- the instance to be assigned a cluster.- Returns:
- an array containing the estimated membership probabilities of the test instance in each cluster (this should sum to at most 1)
- Throws:
java.lang.Exception- if distribution could not be computed successfully
-
getCapabilities
public Capabilities getCapabilities()
Description copied from class:AbstractClustererReturns the Capabilities of this clusterer. Derived classifiers have to override this method to enable capabilities.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Specified by:
getCapabilitiesin interfaceClusterer- Overrides:
getCapabilitiesin classAbstractClusterer- Returns:
- the capabilities of this object
- See Also:
Capabilities
-
numberOfClusters
public int numberOfClusters() throws java.lang.ExceptionDescription copied from class:AbstractClustererReturns the number of clusters.- Specified by:
numberOfClustersin interfaceClusterer- Specified by:
numberOfClustersin classAbstractClusterer- Returns:
- the number of clusters generated for a training dataset.
- Throws:
java.lang.Exception- if number of clusters could not be returned successfully
-
listOptions
public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options. Valid options are:- Specified by:
setOptionsin interfaceOptionHandler- Parameters:
options- the list of options as an array of strings- Throws:
java.lang.Exception- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the clusterer.- Specified by:
getOptionsin interfaceOptionHandler- Returns:
- an array of strings suitable for passing to setOptions()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setDebug
public void setDebug(boolean debug)
Set debugging mode.- Parameters:
debug- true if debug output should be printed
-
getDebug
public boolean getDebug()
Get whether debugging is turned on.- Returns:
- true if debugging output is on
-
getDistanceIsBranchLength
public boolean getDistanceIsBranchLength()
-
setDistanceIsBranchLength
public void setDistanceIsBranchLength(boolean bDistanceIsHeight)
-
distanceIsBranchLengthTipText
public java.lang.String distanceIsBranchLengthTipText()
-
debugTipText
public java.lang.String debugTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
numClustersTipText
public java.lang.String numClustersTipText()
- Returns:
- a string to describe the NumClusters
-
printNewickTipText
public java.lang.String printNewickTipText()
- Returns:
- a string to describe the print Newick flag
-
distanceFunctionTipText
public java.lang.String distanceFunctionTipText()
- Returns:
- a string to describe the distance function
-
linkTypeTipText
public java.lang.String linkTypeTipText()
- Returns:
- a string to describe the Link type
-
globalInfo
public java.lang.String globalInfo()
This will return a string describing the clusterer.- Returns:
- The string.
-
main
public static void main(java.lang.String[] argv)
-
graph
public java.lang.String graph() throws java.lang.ExceptionDescription copied from interface:DrawableReturns a string that describes a graph representing the object. The string should be in XMLBIF ver. 0.3 format if the graph is a BayesNet, otherwise it should be in dotty format.
-
graphType
public int graphType()
Description copied from interface:DrawableReturns the type of graph representing the object.
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classAbstractClusterer- Returns:
- the revision
-
-