클러스터링 살펴보기
이제 바로 앞 연습 문제에서 수행한 클러스터링 결과를 직접 살펴보겠습니다!
이전 연습 문제의 풀이가 이미 실행되어, new_points는 포인트 배열이고 labels는 해당 포인트의 클러스터 레이블 배열이에요.
이 연습은 강의의 일부입니다
Python으로 배우는 Unsupervised Learning
연습 안내
matplotlib.pyplot을plt로 import하세요.new_points의0번 열을xs에,1번 열을ys에 할당하세요.xs와ys의 산점도를 그리고, 포인트를 클러스터 레이블에 따라 색칠하도록 키워드 인자c=labels를 지정하세요. 또한alpha=0.5를 지정하세요.model의.cluster_centers_속성을 사용해 중심(centroids)의 좌표를 계산하세요.centroids의0번 열을centroids_x에,1번 열을centroids_y에 할당하세요.centroids_x와centroids_y의 산점도를 그리고,marker매개변수로'D'(다이아몬드)를 지정해 마커 모양을 설정하세요. 마커 크기는s=50으로 설정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import pyplot
____
# Assign the columns of new_points: xs and ys
xs = ____
ys = ____
# Make a scatter plot of xs and ys, using labels to define the colors
____
# Assign the cluster centers: centroids
centroids = ____
# Assign the columns of centroids: centroids_x, centroids_y
centroids_x = centroids[:,0]
centroids_y = centroids[:,1]
# Make a scatter plot of centroids_x and centroids_y
____
plt.show()