Let's declare the K-means algorithm class, KMeans, with its public methods.
The KMeans class takes the number of clusters, K, and the maximum number of iterations, maxIters, as parameters. The implicit conversion of type T to a Double is specified by the T <% Double view bound. The Ordering class has to be passed implicitly as a parameter because it is required by the sortWith method in the initialize and maxBy methods. The Manifest method is required to preserve the type erasure for Array[T] in the JVM: