I have the following dataset:
node bc cluster
1 russian 0.457039 1
48 man 0.286875 1
155 woman 0.129939 0
3 bit 0.092721 0
5 write 0.065424 0
98 age 0.064347 0
97 escap 0.062675 0
74 game 0.062606 0
Then I perform kMeans clustering by bc
value to separate the nodes into two different groups. Right now with the code below I get the result above (the clustering result is in the cluster
column).
bc_df = pd.DataFrame({"node": bc_nodes, "bc": bc_values})
bc_df = bc_df.sort_values("bc", ascending=False)
km = KMeans(n_clusters=2).fit(bc_df[['bc']])
bc_df.loc[:,'cluster'] = km.labels_
print(bc_df.head(8))
Which is pretty good, but I would like it to work slightly differently and to select the first 4 nodes into the first cluster and then the other ones in the 2nd one, because they are more similar to each other.
Can I do some adjustment to kMeans or maybe you know another algorithm in sklearn
that can do that?