0

I have data points represented on a 2D graph which is shown as below.

1,1
1,2
2,1
2,2
3,3
8,8
9,8
8,9
9,9

EDIT: Now, if I have two initial given clusters, let's say (1,1) and (2,1), I want to use K means to decide the clusters based on Euclidean Distances with termination condition of 3 iterations.

My approach was to create a pandas dataframe, apply kmeans with 2 clusters and note the centroids.

import pandas as pd
df = pd.DataFrame({'x': [1,1,2,2,3,8,9,8,9], 
                   'y': [1,2,1,23,8,8,9,9]})
from sklearn.cluster import KMeans
kmeans = KMeans(2).fit(df.values)

But, I am stuck. How can i define my own customise function for the same.

I want to iterate it to three next iterations and note the calculations to reach the exact clusters in those three iterations.

Thanks

Shivam
  • 171
  • 1
  • 4
  • 16
  • what is your expected / desired output? – MaxU - stand with Ukraine Mar 28 '18 at 09:34
  • @MaxU I want to iterate it to three next iterations and note the calculations to reach the exact clusters – Shivam Mar 28 '18 at 09:41
  • Please read [how to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and edit your post correspondingly. – MaxU - stand with Ukraine Mar 28 '18 at 09:42
  • @MaxU, I have edited my question. Thanks for pointing out, can you please suggest me. – Shivam Mar 28 '18 at 09:50
  • you have you input data set and at the end you will have your desired data set. If you can't imagine how it will look like for this sample data set - how should we help you? If you know what you want to get at the end - put your __desired__ data set to your question – MaxU - stand with Ukraine Mar 28 '18 at 09:53
  • the question is very unclear especially the last couple of sentences... can you elaborate – shahaf Mar 28 '18 at 09:54
  • @MaxU and Shahaf, I have edited the question, please ignore the code for fitting kmeans, that was my approach. I have highlighted, what I need to do. I hope, it makes sense. – Shivam Mar 28 '18 at 09:57
  • @Shivam, i don't see your desired data set (as a data set) in your question. This makes me think, that you _don't know_ exactly what do you want to get at the end. So I can't help you... – MaxU - stand with Ukraine Mar 28 '18 at 10:00
  • @MaxU, If I am correct, I am saying that, we have defined two intial centroids or initial clusters, which I need to iterate again with kmeans and get more accurate clusters which are basically (1,1) and (2,1) for initial consideration. The output will be the two cluster points which are ore accurate than we considered initially. – Shivam Mar 28 '18 at 14:32
  • k-means that uses initial fixed clusters isn't k-means it just algo to calculate the dist of each point to those initial points and assign the arg min, @Shivam is that what you meant? – shahaf Mar 31 '18 at 16:56

0 Answers0