kmeans#

swordfish.function.kmeans()#

K-means clustering.

Parameters:
  • X (Constant) – A table. Each row is an observation and each column is a feature.

  • k (Constant) – A positive integer indicating the number of clusters to form.

  • maxIter (Constant) – A positive integer indicating the maximum number of iterations of the k-means algorithm for a single run. The default value is 300.

  • randomSeed (Constant) – An integer indicating the seed in the random number generator.

  • init (Constant) –

    A STRING scalar or matrix indicating the optional method for initialization. The default value is “random”.

    • If init is a STRING scalar, it can be “random” or “k-means++”: “random” means to choose observations at random from data for the initial centroids; “k-means++” means to generate cluster centroids using the k-means++ algorithm.

    • If init is a matrix, it indicates the centroid starting locations. The number of columns is the same as X and the number of rows is k.

Returns:

A dictionary with the following keys:

  • centers: a k*m (m is the number of columns of X) matrix. Each row is the coordinates of a cluster center.

  • predict: a clustering function for prediction of FUNCTIONDEF type.

  • modelName: string “KMeans”.

  • model: a RESOURCE data type variable. It is an internal binary resource generated by function kmeans to be used by function predict.

  • labels: a vector indicating which cluster each row of X belongs to.

Return type:

Constant