import pandas as pd
df=pd.read_csv('new.csv')
from sklearn.cluster import KMeans
ob=KMeans(n_clusters=3)
ob.fit(df)
print('centroids',ob.cluster_centers_)
print('cluster for each label',ob.labels_)
print('number of clusters',ob.n_clusters)
Output:
Training Data
2
4
6
3
31
12
15
16
38
35
14
21
23
25
30
centroids [[18.] [33.5] [4.33333333]]
cluster for each label [2 2 2 1 0 0 0 1 1 0 0 0 0 1]
number of clusters 3
No comments:
Post a Comment