-
Notifications
You must be signed in to change notification settings - Fork 10
/
2. poor.py
35 lines (24 loc) · 802 Bytes
/
2. poor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import codecademylib3_seaborn
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
from copy import deepcopy
from sklearn.cluster import KMeans
x = [1, 1, 4, 4]
y = [1, 3, 1, 3]
values = np.array(list(zip(x, y)))
centroids_x = [2.5, 2.5]
centroids_y = [1, 3]
centroids = np.array(list(zip(centroids_x, centroids_y)))
model = KMeans(init=centroids, n_clusters=2)
# Initial centroids
# plt.scatter(centroids[:, 0], centroids[:, 1], marker='D', s=100)
results = model.fit_predict(values)
plt.scatter(x, y, c=results, alpha=1)
# Cluster centers
plt.scatter(model.cluster_centers_[:, 0], model.cluster_centers_[:, 1], marker='v', s=100)
ax = plt.subplot()
ax.set_xticks([0, 1, 2, 3, 4, 5])
ax.set_yticks([0, 1, 2, 3, 4])
plt.title('Unlucky Initialization')
plt.show()