시작하기무료로 시작하기

클러스터링 살펴보기

이제 바로 앞 연습 문제에서 수행한 클러스터링 결과를 직접 살펴보겠습니다!

이전 연습 문제의 풀이가 이미 실행되어, new_points는 포인트 배열이고 labels는 해당 포인트의 클러스터 레이블 배열이에요.

이 연습은 강의의 일부입니다

Python으로 배우는 Unsupervised Learning

강의 보기

연습 안내

  • matplotlib.pyplotplt로 import하세요.
  • new_points0번 열을 xs에, 1번 열을 ys에 할당하세요.
  • xsys의 산점도를 그리고, 포인트를 클러스터 레이블에 따라 색칠하도록 키워드 인자 c=labels를 지정하세요. 또한 alpha=0.5를 지정하세요.
  • model.cluster_centers_ 속성을 사용해 중심(centroids)의 좌표를 계산하세요.
  • centroids0번 열을 centroids_x에, 1번 열을 centroids_y에 할당하세요.
  • centroids_xcentroids_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()
코드 편집 및 실행