KMeans is an unsupervised machine learning model that predicts which cluster that the input belongs to using distance.
Contains a matrix.
Create new model object. If any of the arguments are nil, default argument values for that argument will be used.
KMeans.new(maximumNumberOfIterations: integer, numberOfClusters: integer, distanceFunction: string, setInitialClustersOnDataPoints: boolean, setTheCentroidsDistanceFarthest: boolean): ModelObject
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 (Default)
Manhattan
Cosine
setInitialClustersOnDataPoints: Set whether or not the model to create centroids on any data points.
setTheCentroidsDistanceFarthest: Set whether or not the model to create centroids that are furthest from each other. This can only take effect if the “setInitialClustersOnDataPoints” is set to true.
Set model’s parameters. When any of the arguments are nil, previous argument values for that argument will be used.
KMeans:setParameters(maximumNumberOfIterations: integer, numberOfClusters: integer, distanceFunction: string, setInitialClustersOnDataPoints: boolean, setTheCentroidsDistanceFarthest: boolean)
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
setInitialClustersOnDataPoints: Set whether or not the model to create centroids on any data points.
setTheCentroidsDistanceFarthest: Set whether or not the model to create centroids that are furthest from each other. This can only take effect if the “setInitialClustersOnDataPoints” is set to true.
Train the model.
KMeans:train(featureMatrix: Matrix)
Predict which clusters does it belong to for a given data.
KMeans:predict(featureMatrix: Matrix): integer, number
clusterNumber: The cluster which the data belongs to.