Package weka.clusterers
Class HierarchicalClusterer
- java.lang.Object
-
- weka.clusterers.AbstractClusterer
-
- weka.clusterers.HierarchicalClusterer
-
- All Implemented Interfaces:
Serializable,Cloneable,Clusterer,CapabilitiesHandler,CapabilitiesIgnorer,CommandlineRunnable,Drawable,OptionHandler,RevisionHandler
public class HierarchicalClusterer extends AbstractClusterer implements OptionHandler, 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|ADJCOMPLETE|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$
- 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.StringdistanceFunctionTipText()StringdistanceIsBranchLengthTipText()double[]distributionForInstance(Instance instance)Predicts the cluster memberships for a given instance.CapabilitiesgetCapabilities()Returns the Capabilities of this clusterer.DistanceFunctiongetDistanceFunction()booleangetDistanceIsBranchLength()SelectedTaggetLinkType()intgetNumClusters()String[]getOptions()Gets the current settings of the clusterer.booleangetPrintNewick()StringgetRevision()Returns the revision string.StringglobalInfo()This will return a string describing the clusterer.Stringgraph()Returns a string that describes a graph representing the object.intgraphType()Returns the type of graph representing the object.StringlinkTypeTipText()Enumeration<Option>listOptions()Returns an enumeration describing the available options.static voidmain(String[] argv)intnumberOfClusters()Returns the number of clusters.StringnumClustersTipText()StringprintNewickTipText()voidsetDistanceFunction(DistanceFunction distanceFunction)voidsetDistanceIsBranchLength(boolean bDistanceIsHeight)voidsetLinkType(SelectedTag newLinkType)voidsetNumClusters(int nClusters)voidsetOptions(String[] options)Parses a given list of options.voidsetPrintNewick(boolean bPrintNewick)StringtoString()-
Methods inherited from class weka.clusterers.AbstractClusterer
debugTipText, doNotCheckCapabilitiesTipText, forName, getDebug, getDoNotCheckCapabilities, makeCopies, makeCopy, postExecution, preExecution, run, runClusterer, setDebug, setDoNotCheckCapabilities
-
-
-
-
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 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:
Exception- if the clusterer has not been generated successfully
-
clusterInstance
public int clusterInstance(Instance instance) throws 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:
Exception- if instance could not be clustered successfully
-
distributionForInstance
public double[] distributionForInstance(Instance instance) throws 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:
Exception- if distribution could not be computed successfully
-
getCapabilities
public Capabilities getCapabilities()
Description copied from class:AbstractClustererReturns the Capabilities of this clusterer. Derived clusterers 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 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:
Exception- if number of clusters could not be returned successfully
-
listOptions
public Enumeration<Option> listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classAbstractClusterer- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(String[] options) throws Exception
Parses a given list of options. Valid options are:- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classAbstractClusterer- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
getOptions
public String[] getOptions()
Gets the current settings of the clusterer.- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classAbstractClusterer- Returns:
- an array of strings suitable for passing to setOptions()
-
getDistanceIsBranchLength
public boolean getDistanceIsBranchLength()
-
setDistanceIsBranchLength
public void setDistanceIsBranchLength(boolean bDistanceIsHeight)
-
distanceIsBranchLengthTipText
public String distanceIsBranchLengthTipText()
-
numClustersTipText
public String numClustersTipText()
- Returns:
- a string to describe the NumClusters
-
printNewickTipText
public String printNewickTipText()
- Returns:
- a string to describe the print Newick flag
-
distanceFunctionTipText
public String distanceFunctionTipText()
- Returns:
- a string to describe the distance function
-
linkTypeTipText
public String linkTypeTipText()
- Returns:
- a string to describe the Link type
-
globalInfo
public String globalInfo()
This will return a string describing the clusterer.- Returns:
- The string.
-
main
public static void main(String[] argv)
-
graph
public String graph() throws Exception
Description 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 String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classAbstractClusterer- Returns:
- the revision
-
-