May 2020
Intermediate to advanced
530 pages
17h 8m
English
The Shark-ML library implements the k-means algorithm in the kMeans() function, which takes three parameters: the training dataset, the desired number of clusters, and the output parameter for cluster centroids. The following code sample shows how to use this function:
UnlabeledData<RealVector> features; int num_clusters = 2; ... Centroids centroids; kMeans(features, num_clusters, centroids);
After we get the centroids, we can initialize an object of the HardClusteringModel class. As in the previous example, we can use this object for the evaluation of the trained model on new data or the training data, as follows:
HardClusteringModel<RealVector> model(¢roids); Data<unsigned> clusters = model(features); ...
Read now
Unlock full access