Python Machine Learning

KMean

Data Sample

X1X2
210
25
84
58
75
64
12
49
X = [
    [2, 10],
    [2, 5],
    [8, 4],
    [5, 8],
    [7, 5],
    [6, 4],
    [1, 2],
    [4, 9]
]

Build model

from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters = 3, n_init='auto')
kmeans.fit(X)

View Clusters

kmeans.labels_

Cluster Center

kmeans.cluster_centers_

Predict

kmeans.predict([[1, 3], [2, 8]])