import pandas as pd from sklearn cluster import KMeans data 10 12 24 1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pandas as pd
from sklearn.cluster import KMeans
data = [(0.2, 10),
(0.3, 12),
(0.24, 14),
(0.8, 30),
(0.9, 32),
(0.85, 33.3),
(0.91, 31),
(0.1, 15),
(-0.23, 45)]
p_df = pd.DataFrame(data)
kmeans = KMeans(init='k-means++', n_clusters=3, n_init=10)
kmeans.fit(p_df)
Result:
>>> kmeans.labels_
array([0, 0, 0, 2, 2, 2, 2, 0, 1], dtype=int32)