Package cc.mallet.cluster
Class KMeans
- java.lang.Object
-
- cc.mallet.cluster.Clusterer
-
- cc.mallet.cluster.KMeans
-
- All Implemented Interfaces:
java.io.Serializable
public class KMeans extends Clusterer
KMeans Clusterer Clusters the points into k clusters by minimizing the total intra-cluster variance. It uses a givenMetric
to find the distance betweenInstance
s, which should haveSparseVector
s in the data field.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
EMPTY_DROP
Drop an empty clusterstatic int
EMPTY_ERROR
Treat an empty cluster as an error condition.static int
EMPTY_SINGLE
Place the single instance furthest from the previous cluster mean
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Clustering
cluster(InstanceList instances)
Cluster instancesjava.util.ArrayList<SparseVector>
getClusterMeans()
Return the ArrayList of cluster means after a run of the algorithm.
-
-
-
Field Detail
-
EMPTY_ERROR
public static final int EMPTY_ERROR
Treat an empty cluster as an error condition.- See Also:
- Constant Field Values
-
EMPTY_DROP
public static final int EMPTY_DROP
Drop an empty cluster- See Also:
- Constant Field Values
-
EMPTY_SINGLE
public static final int EMPTY_SINGLE
Place the single instance furthest from the previous cluster mean- See Also:
- Constant Field Values
-
-
Constructor Detail
-
KMeans
public KMeans(Pipe instancePipe, int numClusters, Metric metric, int emptyAction)
Construct a KMeans object- Parameters:
instancePipe
- Pipe for the instances being clusterednumClusters
- Number of clusters to usemetric
- Metric object to measure instance distancesemptyAction
- Specify what should happen when an empty cluster occurs
-
KMeans
public KMeans(Pipe instancePipe, int numClusters, Metric metric)
Construct a KMeans object- Parameters:
instancePipe
- Pipe for the instances being clusterednumClusters
- Number of clusters to usemetric
- Metric object to measure instance distances If an empty cluster occurs, it is considered an error.
-
-
Method Detail
-
cluster
public Clustering cluster(InstanceList instances)
Cluster instances
-
getClusterMeans
public java.util.ArrayList<SparseVector> getClusterMeans()
Return the ArrayList of cluster means after a run of the algorithm.- Returns:
- An ArrayList of Instances.
-
-