Perform the clustering algorithm k-means, which split a set of points into k clusters.
using kMeansClustering
mat = rand(3,100) # generate 100 3-dimensional points
r = mykmeansclustering(mat,4) # organize mat in k=4 clusters
r[1] -> centers
r[2] -> total cost
r[3] -> assignments
r[4] -> initial centers used (Forgy method)
using RDatasets, kMeansClustering, Plots
iris = dataset("datasets", "iris");
features = collect(Matrix(iris[:, 1:4])');
r = mykmeansclustering(features, 3); # split data into k=3 clusters
scatter(iris.PetalLength, iris.PetalWidth, marker_z=r[3],
color=:lightrainbow, legend=false)