Professional Documents
Culture Documents
7.kmeans - Jupyter Notebook
7.kmeans - Jupyter Notebook
In [3]: 1 plt.scatter(X[:,0],X[:,1],c=Y)
In [4]: 1 k=5
2
3 colors = ["green","yellow","red","blue","orange"]
4 clusters = {}
5
6 for i in range(k):
7 center = 10*(2*np.random.random((X.shape[1],))-1)
8 points = []
9
10 cluster = {
11 'center':center,
12 'points':points,
13 'color':colors[i]
14 }
15
16 clusters[i] = cluster
http://localhost:8888/notebooks/Desktop/FOOD/NSIT/Pattern%20Recognition/7.kmeans.ipynb Page 1 of 3
7.kmeans - Jupyter Notebook 11/03/20, 2(16 AM
In [5]: 1 clusters
In [8]: 1 maxEpochs = 20
2 for i in range(maxEpochs):
3 assignclusters(X,clusters)
4 updateClusters(X,clusters)
http://localhost:8888/notebooks/Desktop/FOOD/NSIT/Pattern%20Recognition/7.kmeans.ipynb Page 2 of 3
7.kmeans - Jupyter Notebook 11/03/20, 2(16 AM
In [10]: 1 assignclusters(X,clusters)
2 plotclusters(X,clusters)
(99, 2)
(103, 2)
(98, 2)
(100, 2)
(100, 2)
In [ ]: 1
http://localhost:8888/notebooks/Desktop/FOOD/NSIT/Pattern%20Recognition/7.kmeans.ipynb Page 3 of 3