API Reference - Models - KMedoids

KMedoids is an unsupervised machine learning model that assigns data points to clusters by selecting representative points, called medoids, as cluster centers. It then predicts the cluster membership of new data points based on their distances to the medoids.

Stored Model Parameters

Contains a matrix.

  • ModelParameters[I][J]: Value of matrix at row I and column J. The rows represent the clusters. The columns represent the features.

Constructors

new()

Create new model object. If any of the arguments are nil, default argument values for that argument will be used.

KMedoids.new(maximumNumberOfIterations: integer, numberOfClusters: integer, distanceFunction: string, setTheCentroidsDistanceFarthest: boolean): ModelObject

Parameters:

  • maximumNumberOfIterations: How many times should the model needed to be trained.

  • numberOfClusters: Number of clusters for model to train and predict on.

  • distanceFunction: The function that the model will use to train. distanceFunction available are:

    • Euclidean

    • Manhattan

    • Cosine

  • setTheCentroidsDistanceFarthest: Set whether or not the model to create centroids that are furthest from each other.

Returns:

  • ModelObject: The generated model object.

Functions

train()

Train the model.

KMedoids:train(featureMatrix: Matrix)

Parameters:

  • featureMatrix: Matrix containing all data.

Returns:

  • costArray: An array containing cost values.

predict()

Predict which clusters does it belong to for a given data.

KMedoids:predict(featureMatrix: Matrix, returnOriginalOutput: boolean): Matrix, Matrix -OR- Matrix

Parameters:

  • featureMatrix: Matrix containing data.

  • returnOriginalOutput: Set whether or not to return distance matrix instead of clusterNumberVector and closestDistanceVector.

Returns:

  • clusterNumberVector: A vector containing which cluster that the data belongs to.

  • closestDistanceVector: A vector containing the closest distance between the datapoint and the center of the cluster (centroids).

-OR-

  • distanceMatrix: A matrix containing data-cluster pair distance.

Returns:

  • clusterNumber: The cluster which the data belongs to.

  • shortestDistance: The distance between the datapoint and the center of the cluster (centroids).

Inherited From