[부스트캠프 AI Tech 5기] Seaborn

박상우·2023년 3월 27일
0

부스트캠프

목록 보기
24/54
post-thumbnail

Seaborn

Seaborn 기초

  • Categorical API
  • Distributional API
  • Relational API
  • Regression API
  • Matrix API

Seabron의 기본 인자

  • x,y,hue (feature)
  • data (dataframe)
  • palette(종합적인 색상 팔레트), color(단위 색상)
  • order (순서 지정)
  • matplotlib와 함께 ax를 지정하여 그릴 수 있음
sns.countplot(x='race',data=student,
			  hue = 'gender',
              hue_order = sorted(student['gender'].unique()),
              ax = axes[1]]

Categorical API

Box Plot

sns.boxplot(x='math score',data=student) 

Violin Plot

  • 실제 분포에 대한 정보를 제공하기 적합한 방식
  • 일종의 Histogram의 보간
  • 데이터가 연속적이지 않은데, 연속적으로 보이기 때문에 오해가 생길 가능성이 높음
  • bw 수치를 조정하여 연속의 강도를 지정
  • split으로 반반씩 hue 비교 가능
sns.violinplot(x='math score',data=student) 

Distribution API

Univariate Distribution

Histogram

  • 히스토그램
  • binwidth, bins로 막대 간격 조정
  • multiple = 'fill', 'dodge', 'stack','layer' 등으로 multiple 방법론 사용 가능
sns.histplot(x='math score',data=student) 

KDEplot

  • 선으로 표현
  • fill = True로 밀도를 채울 수 있음
  • multiple = 'fill','stack','layer'
  • cumulative = True로 CDF로 변경 가능
sns.kdeplot(x='math score',data=student) 

Bivariate Distribution

Histplot

  • scatter plot 보다 가독성이 좋음
sns.histplot(x='math score', y='reading score', data=student)

KDEplot

  • scatter plot 보다 가독성이 좋음
sns.kdeplot(x='math score', y='reading score', data=student)

Relation & Regression

Scatter Plot

sns.scatterplot(x='math score', y='reading score', data=student)

Line Plot

  • 알아서 평균과 표준 편차로 오차 범위를 정해줌
sns.lineplot(x='math score', y='reading score', data=student)

Regplot

  • order = int로 차원 설정 가능
sns.regplot(x='math score', y='reading score', data=student)

Matrix Plot

Heatmap

sns.heatmap(heart.corr(), ax=ax,
			vmin = -1, vmax= 1, center=0,
            cmap = 'coolwarm',
            annot=True, fmt='.2f'
            )

Multi Chart

Jointplot

  • 결합 확률분포와 각각의 분포를 살필 수 있는 시각화
  • kind = 'scatter','kde','hist','hex','reg','resid' 등으로 내부 type 지정 가능
sns.jointplot(x='math score', y= 'reading score', data= student, hue='gender)

Pairplot

  • 데이터의 pair-wise 관계를 시각화 하는 함수
  • kind = 'scatter','kde','hist','reg'
  • diag_kin = 'auto','hist','kde',None
sns.pairplot(data=iris,hue='Species')

Facet Grid 사용

  • feature의 category의 관계를 살펴 볼 수 있음
sns.catplot(x='race',y='math score',data=student,
			kind = 'box',col='lunch')
            
sns.displot(x='race',hue='gender',data=student)

sns.relplot(x='math score',y='reading score',
			hue='gender', data=student, col='lunch')
profile
세상아 덤벼라

0개의 댓글