An alternative algorithm to sklearn KMeans that separates values by similarity? 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?
Welcome, Dmitry!

A very first red alarm ... If you are doing clustering, then let it tell you who is similar to who! If you already know your clusters, then why are you doing clustering indeed?!

And about the algorithms: Yes there are many more, for example, Spectral Clustering which makes use of different similarity measures (via Gaussian Kernel or K-NN connectivity matrix) to find clusters or DBSCAN which is based on similarity according to the density of data points.

If you needed more help please drop a comment here!

Good Luck!