Click or drag to resize

KMeansClustering Class

Class KMeansClustering performs k-means clustering on a set of data points.
Inheritance Hierarchy
SystemObject
  CenterSpace.NMath.CoreKMeansClustering

Namespace: CenterSpace.NMath.Core
Assembly: NMath (in NMath.dll) Version: 7.4
Syntax
[SerializableAttribute]
public class KMeansClustering : ICloneable

The KMeansClustering type exposes the following members.

Constructors
 NameDescription
Protected methodKMeansClustering Constructs an empty KMeansClustering instance.
Public methodKMeansClustering(DataFrame) Constructs a KMeansClustering instance from the given data.
Public methodKMeansClustering(DoubleMatrix) Constructs a KMeansClustering instance from the given data.
Public methodKMeansClustering(DataFrame, Int32) Constructs a KMeansClustering instance from the given data and the specified maximum number of iterations.
Public methodKMeansClustering(DoubleMatrix, Int32) Constructs a KMeansClustering instance from the given data and the specified maximum number of iterations.
Top
Properties
 NameDescription
Public propertyClusters Gets the cluster assignments computed during the last clustering.
Public propertyData Gets and sets the data matrix.
Public propertyStatic memberDefaultMaxIterations Gets and sets the default maximum number of iterations.
Public propertyFinalCenters Gets the matrix of final cluster centers computed during the last clustering.
Public propertyInitialCenters Gets the matrix of initial cluster centers used during the last clustering.
Public propertyIterations Gets the number of iterations used in the clustering just computed.
Public propertyK Gets the number of clusters computed during the last clustering..
Public propertyMaxIterations Gets and sets the maximum number of iterations used in clustering.
Public propertyMaxIterationsMet Returns true if the clustering just computed stopped because the maximum number of iterations was reached; otherwise, false.
Public propertyN Gets the number of objects in this.Data.
Public propertySizes Gets the number of points in each cluster computed during the last clustering.
Public propertyWithinSumOfSquares Gets the within-cluster sum of squares for each cluster computed during the last clustering.
Top
Methods
 NameDescription
Public methodClone Creates a deep copy of this cluster analysis.
Public methodCluster(DoubleMatrix) Clusters the data into the specified number of clusters.
Public methodCluster(Int32) Clusters the data into the specified number of clusters.
Public methodCluster(Int32, KMeansClusteringStart) Clusters the data into the specified number of clusters, using the specified method of choosing the initial cluster centers.
Public methodCluster(Int32, RandGenMTwist) Clusters the data into the specified number of clusters.
Top
Fields
 NameDescription
Protected fieldclusters_The cluster assigments.
Protected fielddata_ A matrix of data. Each row in the matrix represents an object to be clustered.
Protected fieldStatic memberDEFAULT_MAX_ITERThe default maximum number of iterations.
Protected fieldfinalCenters_ A matrix of final cluster centers.
Protected fieldinitialCenters_ A matrix of initial cluster centers.
Protected fielditer_The number of iterations performed.
Protected fieldmax_The maximum number of iterations.
Protected fieldsizes_ The number of objects in each cluster.
Protected fieldwithinss_ The within-cluster sum of squares for each cluster.
Top
Remarks
The k-means method assigns points into k groups such that the sum of squares from points to the computed cluster centers is minimized.
The algorithm used by class KMeansClustering is that of Hartigan and Wong (A K-means clustering algorithm. Applied Statistics 28, 100–108. 1979). The algorithm is iterative: For each point, move it to another cluster if that would lower the energy. If you move a point, immediately update the cluster centers of the two affected clusters. Repeat until no points are moved, or the specified maximum number of iterations is reached.
Instances of class KMeansClustering are constructed from a matrix of data, where each row in the matrix represents an object to be clustered.
Example
C#
// cluster 8 random vectors of length 3
DoubleMatrix data = new DoubleMatrix( 8, 3, new RandGenUniform() );
KMeansClustering cl = new KMeansClustering( data );

// create 3 clusters, using random starting cluster centers
ClusterSet clusters = cl.Cluster( 3 );
See Also