mulan.classifier.meta
Class ConstrainedKMeans

java.lang.Object
  extended by weka.clusterers.AbstractClusterer
      extended by weka.clusterers.RandomizableClusterer
          extended by mulan.classifier.meta.ConstrainedKMeans
All Implemented Interfaces:
Serializable, Cloneable, Clusterer, NumberOfClustersRequestable, CapabilitiesHandler, OptionHandler, Randomizable, RevisionHandler, WeightedInstancesHandler

public class ConstrainedKMeans
extends RandomizableClusterer
implements NumberOfClustersRequestable, WeightedInstancesHandler

Cluster data using the constrained k means algorithm

Version:
2012.07.16
Author:
Mark Hall, Eibe Frank, Grigorios Tsoumakas
See Also:
RandomizableClusterer, Serialized Form

Nested Class Summary
static class ConstrainedKMeans.bucketInstance
          Class for representing an instance inside a bucket
 
Field Summary
 
Fields inherited from class weka.clusterers.RandomizableClusterer
m_Seed, m_SeedDefault
 
Constructor Summary
ConstrainedKMeans()
          the default constructor
 
Method Summary
 void buildClusterer(Instances data)
          Generates a clusterer.
 int clusterInstance(Instance instance)
          Classifies a given instance.
 Capabilities getCapabilities()
          Returns default capabilities of the clusterer.
 Instances getClusterCentroids()
          Gets the the cluster centroids
 int[][][] getClusterNominalCounts()
          Returns for each cluster the frequency counts for the values of each nominal attribute
 int[] getClusterSizes()
          Gets the number of instances in each cluster
 Instances getClusterStandardDevs()
          Gets the standard deviations of the numeric attributes in each cluster
 int getNumClusters()
          gets the number of clusters to generate
 double getSquaredError()
          Gets the squared error for all clusters
 String globalInfo()
          Returns a string describing this clusterer
 Enumeration listOptions()
          Returns an enumeration describing the available options.
 int numberOfClusters()
          Returns the number of clusters.
 String numClustersTipText()
          Returns the tip text for this property
 void setMaxIterations(int x)
           
 void setNumClusters(int n)
          set the number of clusters to generate
 String toString()
          return a string describing this clusterer
 
Methods inherited from class weka.clusterers.RandomizableClusterer
getOptions, getSeed, seedTipText, setOptions, setSeed
 
Methods inherited from class weka.clusterers.AbstractClusterer
distributionForInstance, forName, getRevision, makeCopies, makeCopy, runClusterer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstrainedKMeans

public ConstrainedKMeans()
the default constructor

Method Detail

globalInfo

public String globalInfo()
Returns a string describing this clusterer

Returns:
a description of the evaluator suitable for displaying in the explorer/experimenter gui

getCapabilities

public Capabilities getCapabilities()
Returns default capabilities of the clusterer.

Specified by:
getCapabilities in interface Clusterer
Specified by:
getCapabilities in interface CapabilitiesHandler
Overrides:
getCapabilities in class AbstractClusterer
Returns:
the capabilities of this clusterer

setMaxIterations

public void setMaxIterations(int x)
Parameters:
x -

buildClusterer

public void buildClusterer(Instances data)
                    throws Exception
Generates a clusterer. Has to initialize all fields of the clusterer that are not being set via options.

Specified by:
buildClusterer in interface Clusterer
Specified by:
buildClusterer in class AbstractClusterer
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
Classifies a given instance.

Specified by:
clusterInstance in interface Clusterer
Overrides:
clusterInstance in class AbstractClusterer
Parameters:
instance - the instance to be assigned to a cluster
Returns:
the number of the assigned cluster as an interger if the class is enumerated, otherwise the predicted value
Throws:
Exception - if instance could not be classified successfully

numberOfClusters

public int numberOfClusters()
                     throws Exception
Returns the number of clusters.

Specified by:
numberOfClusters in interface Clusterer
Specified by:
numberOfClusters in class AbstractClusterer
Returns:
the number of clusters generated for a training dataset.
Throws:
Exception - if number of clusters could not be returned successfully

listOptions

public Enumeration listOptions()
Returns an enumeration describing the available options.

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class RandomizableClusterer
Returns:
an enumeration of all the available options.

numClustersTipText

public String numClustersTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setNumClusters

public void setNumClusters(int n)
                    throws Exception
set the number of clusters to generate

Specified by:
setNumClusters in interface NumberOfClustersRequestable
Parameters:
n - the number of clusters to generate
Throws:
Exception - if number of clusters is negative

getNumClusters

public int getNumClusters()
gets the number of clusters to generate

Returns:
the number of clusters to generate

toString

public String toString()
return a string describing this clusterer

Overrides:
toString in class Object
Returns:
a description of the clusterer as a string

getClusterCentroids

public Instances getClusterCentroids()
Gets the the cluster centroids

Returns:
the cluster centroids

getClusterStandardDevs

public Instances getClusterStandardDevs()
Gets the standard deviations of the numeric attributes in each cluster

Returns:
the standard deviations of the numeric attributes in each cluster

getClusterNominalCounts

public int[][][] getClusterNominalCounts()
Returns for each cluster the frequency counts for the values of each nominal attribute

Returns:
the counts

getSquaredError

public double getSquaredError()
Gets the squared error for all clusters

Returns:
the squared error

getClusterSizes

public int[] getClusterSizes()
Gets the number of instances in each cluster

Returns:
The number of instances in each cluster