상세 컨텐츠

본문 제목

패스트 캠퍼스[데이터분석 강의]_ 데이터시각화 Seaborn

본문

seaborn은 matplotlib기반의 시각화 라이브러리

유익한 통계 기반 그래픽을 그리기 위한 고급 인터페이스를 제공

 

pip install seaborn

import seaborn as sns 

https://seaborn.pydata.org

 

seaborn: statistical data visualization — seaborn 0.13.2 documentation

seaborn: statistical data visualization

seaborn.pydata.org

 

* seaborn 데이터 불러오기

: seaborn 라이브러리에서 제공하는 titanic 데이터 불러오기 

: seaborn의 load_dataset() 함수를 이용 (내장데이터 저장 되어 있어 불러올수 있음) 

https://github.com/mwaskom/seaborn-data

 

GitHub - mwaskom/seaborn-data: Data repository for seaborn examples

Data repository for seaborn examples. Contribute to mwaskom/seaborn-data development by creating an account on GitHub.

github.com

 

* seaborn 선형회귀선 있는 산점도

: regplot() 함수 : 선형 회귀선이 있는 산점도 시각화

: regplot() 함수의 파라미터

 - x축 변수

 - y축 변수

 - 데이터셋

 - axe 객체

 - fit_reg: 선형회귀선 표시여부 

* 선형회귀선 

 - 간단한 선형 데이터 집합에 사용되는 가장 적합한 직선 (= 추세선)

 - 데이터를 시간 축으로 봤을때, 데이터의 값이 장기적으로 어떻게 변하는지 직선으로 표현한것

 

* seaborn 히스토그램과 커널밀도 그래프 

: distplot() 함수 : 히스토그램과 커널 밀도 그래프 시각화

: distplot() 함수의 파라미터

 - 분포를 그릴 데이터 변수

 - hist : True는 히스토그램 표시, False는 히스토그램 표시 안함 

 - kde : True는 커널밀도 그래프 표시, False는 커널밀도 그래프 표시 안함 

 - axe 객체

: histplot() 함수 : 히스토그램(하나의 변수 데이터의 분포를 확인할때 사용하는 함수)

: kdeplot() 함수 : 커널밀도 그래프 (그래프와 x축 사이의 면적이 1이 되도록 그리는 밀도함수) 

/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning) /usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning) /usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `kdeplot` (an axes-level function for kernel density plots). warnings.warn(msg, FutureWarning)

 

* seaborn 범주형 데이터의 산점도 

: stripplot() 함수 : 데이터포인트가 중복되어 범주별 분포를 시각화

: stripplot() 함수의 파라미터

 - x축 변수

 - y축 변수

 - 데이터셋

 - axe 객체

 - hue: 특정열 데이터로 색상을 구분하여 출력 

: swarmplot() 함수 : 데이터의 분산까지 고려하여 데이터 포인트가 서로 중복되지 않도록 시각화

: swarmplot() 함수의 파라미터 

 - x축 변수

 - y축 변수

 - 데이터셋

 - axe 객체

 - hue: 특정열 데이터로 색상을 구분하여 출력

/usr/local/lib/python3.7/dist-packages/seaborn/categorical.py:1296: UserWarning: 8.8% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot. warnings.warn(msg, UserWarning)

 

* seaborn 빈도 그래프

: countplot() 함수 : 각 범주에 속하는 데이터의 개수를 막대 그래프 시각화

: countplot() 함수의 파라미터 

 - x축 변수

 - palette

 - 데이터셋

 - axe 객체

 - hue: 특정열 데이터로 색상을 구분하여 출력

 

* seaborn 조인트 그래프

: joinplot() 함수 : 산점도를 기본으로 표시, x-y 축에 각 변수에 대한 히스토그램을 동시에 시각화

: joinplot() 함수의 파라미터

 - x축 변수

 - y축 변수

 - 데이터셋

 - kind = 'reg' 선형회귀선 추가 

 - kind = 'hex' 육각산점도 추가 

 - kind = 'kde' 커널밀집 그래프 추가 

 

* seaborn 관계 그래프

: pairplot() 함수

  - 인자로 전달되는 데이터프레임의 열(변수)을 두개씩 짝지을수 있는 모든 조합에 대해서 표현

  - 열은 정수/실수형이어야 함

  - 3개의 열이라면 3행 x 3열의 크기로 모두 9개의 그리드 생성

  - 각 그리드의 두 변수간의 관계를 나타내는 그래프를 하나씩 그림

  - 같은 변수끼리 짝을 이루는 대각선 방향으로는 히스토그램 시각화

  - 서로다른 변수간에는 산점도 시각화 

관련글 더보기