클러스터 시각화

Python으로 배우는 군집 분석

Shaumik Daityari

Business Analyst

왜 클러스터를 시각화할까요?

  • 형성된 클러스터를 해석
  • 클러스터 검증의 추가 단계
  • 데이터의 추세 파악
Python으로 배우는 군집 분석

seaborn 소개

  • seaborn: matplotlib 기반의 파이썬 시각화 라이브러리
  • matplotlib보다 미려하고 수정이 쉬운 미학 제공
  • 데이터 분석 맥락의 시각화 작업을 쉽게 하는 함수 제공
  • 클러스터링에서의 사용: 플롯의 hue 매개변수
Python으로 배우는 군집 분석

matplotlib로 클러스터 시각화

from matplotlib import pyplot as plt
df = pd.DataFrame({'x': [2, 3, 5, 6, 2],
                   'y': [1, 1, 5, 5, 2],
                   'labels': ['A', 'A', 'B', 'B', 'A']})

colors = {'A':'red', 'B':'blue'}
df.plot.scatter(x='x', y='y', c=df['labels'].apply(lambda x: colors[x])) plt.show()
Python으로 배우는 군집 분석

seaborn으로 클러스터 시각화

from matplotlib import pyplot as plt
import seaborn as sns
df = pd.DataFrame({'x': [2, 3, 5, 6, 2],
                   'y': [1, 1, 5, 5, 2],
                   'labels': ['A', 'A', 'B', 'B', 'A']})

sns.scatterplot(x='x', y='y', hue='labels', data=df) plt.show()
Python으로 배우는 군집 분석

두 시각화 방법 비교

matplotlib 플롯

seaborn 플롯

Python으로 배우는 군집 분석

다음: 시각화 시도

Python으로 배우는 군집 분석

Preparing Video For Download...