Skip to content

Instantly share code, notes, and snippets.

@maskaravivek
Created May 23, 2020 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maskaravivek/37359884219d9a925d640c5396201f55 to your computer and use it in GitHub Desktop.
Save maskaravivek/37359884219d9a925d640c5396201f55 to your computer and use it in GitHub Desktop.
K = 6;
color = lines(K);
[idx, C, SSE] = kmeans(X, K, 'Distance', 'sqEuclidean', 'Replicates', 10);
totalSSE = sum(SSE);
fprintf('SSE using K-means is %d \n', totalSSE);
figure
gscatter(X(:,1),X(:,2),idx,color(1:K,:))
hold on
plot(C(:,1),C(:,2),'+k', 'MarkerSize', 8, 'LineWidth', 3)
legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4','Cluster 5','Cluster 6','Cluster Centroid')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment