Question: ( 3 ) Clustering ( 2 5 marks ) The class Clustering implements a k - means algorithm adapted from [ 1 , 2 ]
Clustering marksThe class Clustering implements a kmeans algorithm adapted from The class has a single public method: static Cluster kmeansFeatureVector examples, int kThis problem is known to be difficult to solve exactly when the number of examples is large. The kmeans algorithm is an approximate method that makes the "best" local choice at each iteration without consideration of the global solution of the problem. We call this a "greedy" strategy.Comparing the examples to the centroid of the clusters reduces considerably the total number of comparisons as it avoids comparing allagainstall examples and the number of centroids clusters is generally small. This makes the kmeans algorithm quite efficient.Input:The input consists of n examples objects of the class FeatureVector and k the number of clusters to be produced.Output:A partition of the n input examples into k groups clusters The partition is such that the elements of the same cluster are closer to the centroid of the group than they are from the centroid of other clusters.Algorithm: Initialization Create k clusters and let D designate this set of clusters such that Di is the ith cluster of DRandomly select, without replacement, k examples from the n input examples.Each randomly selected example becomes the centroid of a cluster. Repeat Create k clusters and let D designate this set of clusters. For each input example e: If the distance from e to the centroid of Di is minimum., assign e to Di where Di designates the ith cluster of D Updating DCompare the corresponding clusters of D and D If the size or the centroid has changed, then the respective cluster of D replaces that of D If none of the clusters have changed, the algorithm terminates and returns the current clusters. Otherwise, the algorithm resumes
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
