# K-means clustering algorithm in python

I'm looking for a package to use **K-means clustering** algorithm in **python**.

I need just to run clustering algorithm in python from other environment, which is writen in another language.

I'm looking for a package to use **K-means clustering** algorithm in **python**.

I need just to run clustering algorithm in python from other environment, which is writen in another language.

1 Answers

JO

3For running a clustering algorithm from another environment, you can use any package writen in python.

The only thing you should consider, is how you're going to connect those 2 pieces.

You can use different approaches for connecting 2 pieces like

**Rest API****Socket Connection****GRPC****etc.**

and about **k-means clustering algorithm**: you can take scikit-learn implementation, which gives you a simple API to do it

```
from sklearn.cluster import KMeans
import numpy as np
X = np.array([[1, 2], [1, 4], [1, 0],
[10, 2], [10, 4], [10, 0]])
kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
kmeans.labels_ # labels for the cluster
kmeans.cluster_centers_ # centroids for every cluster
kmeans.predict([p1, p2]) # predict the cluster for the points
```

Reply

Couldn't find what you were looking for?and we will find an expert to answer.

How helpful was this page?