import mglearn
import matplotlib.pyplot as plt
### 한글
import matplotlib
from matplotlib import font_manager, rc
font_loc = "C:/Windows/Fonts/malgunbd.ttf"
font_name = font_manager.FontProperties(fname=font_loc).get_name()
matplotlib.rc('font', family=font_name)
mglearn.plots.plot_agglomerative_algorithm()
from sklearn.datasets import make_blobs
from sklearn.cluster import AgglomerativeClustering
X, y = make_blobs(random_state=1)
agg = AgglomerativeClustering(n_clusters=3)
assignment = agg.fit_predict(X) # 클러스터의 소속 정보 얻기
assignment
array([0, 2, 2, 2, 1, 1, 1, 2, 0, 0, 2, 2, 1, 0, 1, 1, 1, 0, 2, 2, 1, 2, 1, 0, 2, 1, 1, 0, 0, 1, 0, 0, 1, 0, 2, 1, 2, 2, 2, 1, 1, 2, 0, 2, 2, 1, 0, 0, 0, 0, 2, 1, 1, 1, 0, 1, 2, 2, 0, 0, 2, 1, 1, 2, 2, 1, 0, 1, 0, 2, 2, 2, 1, 0, 0, 2, 1, 1, 0, 2, 0, 2, 2, 1, 0, 0, 0, 0, 2, 0, 1, 0, 0, 2, 2, 1, 1, 0, 1, 0], dtype=int64)
import matplotlib
matplotlib.rcParams['axes.unicode_minus'] = False
plt.scatter(X[:,0],X[:,1], label="클러스터 1,2,3",
alpha=0.3, edgecolors='none', c=assignment)
plt.legend()
plt.grid(True)
plt.xlabel("특성 0")
plt.ylabel("특성 1")
plt.show()
mglearn.plots.plot_agglomerative()