scikit learn k means 1

scikit learn k means

from sklearn.cluster import KMeans
df = np.array([[1,4],[2,2],[2,5],[3,3],[3,4],[4,7],[5,6],[6,4],[6,7],[7,6],[7,9],[8,7],[8,9],[9,4],[9,8]])
kmeans = KMeans(n_clusters=3, init='k-means++', max_iter=300, n_init=10)
y_pred = kmeans.fit_predict(df)

Here is what the above code is Doing:
1. We are creating an array of data points.
2. We are creating an object of KMeans class.
3. We are fitting the data to the model.
4. We are predicting the clusters.

Similar Posts