回答編集履歴
1
修正
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
```Python
|
3
3
|
import matplotlib.pyplot as plt
|
4
4
|
import numpy as np
|
5
|
-
from scipy.cluster.hierarchy import linkage, fcluster
|
5
|
+
from scipy.cluster.hierarchy import linkage, fcluster, dendrogram
|
6
6
|
import random
|
7
7
|
|
8
8
|
# テストデータ
|
@@ -15,7 +15,12 @@
|
|
15
15
|
|
16
16
|
# クラスタリング
|
17
17
|
Z = linkage(X, method='ward', metric='euclidean')
|
18
|
+
dendrogram(Z)
|
19
|
+
plt.show()
|
20
|
+
|
21
|
+
# クラスタ分け
|
18
22
|
threshold = 0.7 * np.max(Z[:, 2])
|
23
|
+
print(threshold) # 約2.9
|
19
24
|
C = fcluster(Z, threshold, criterion='distance')
|
20
25
|
print(C) # [2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1]
|
21
26
|
|
@@ -23,4 +28,5 @@
|
|
23
28
|
plt.scatter(x1, x2, c=C)
|
24
29
|
plt.show()
|
25
30
|
```
|
31
|
+

|
26
32
|

|