โน๏ธ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/ |
| Last Crawled | 2026-04-10 05:25:10 (18 hours ago) |
| First Indexed | 2023-01-12 14:46:31 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ์ฌํํธ - Snug Archive |
| Meta Description | ์ง๋ ์๊ฐ์๋ ํ์ด์ฌ์ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ๋ณ์๊ฐ 1๊ฐ์ธ ๋จ๋ณ๋ ๋ฐ์ดํฐ(univariate data)๋ฅผ ์๊ฐํํ๋ ๋ฒ์โฆ |
| Meta Canonical | null |
| Boilerpipe Text | ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ
Last Updatedย ย
2024-09-10
Publishedย ย
2023-01-12
Python Seaborn
11๋ถ
๋ชฉ์ฐจ
Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด๋ณด์
์ง๋ ์๊ฐ์๋ ํ์ด์ฌ์ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ๋ณ์๊ฐ 1๊ฐ์ธ ๋จ๋ณ๋ ๋ฐ์ดํฐ(univariate data)๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ ์๊ฐ์๋ ๋ณ์๊ฐ 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ(bivariate data)์ 3๊ฐ ์ด์์ธ ๋ค๋ณ๋ ๋ฐ์ดํฐ(multivariate data)๋ฅผ ์๊ฐํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค. Seaborn ์ฌ์ฉ์ ์ํ ๊ธฐ๋ณธ ํ๊ฒฝ ์ค์ ๋ฐฉ๋ฒ๊ณผ ๊ทธ๋ํ ์คํ์ผ๋ง, 1์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์ถ์ ๋ถ๋ค์
ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ
์ ๋จผ์ ์ฝ์ผ์๊ธฐ๋ฅผ ์ถ์ฒ๋๋ฆฝ๋๋ค.
๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๊ทธ๋ํ์ ์ข
๋ฅ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
๋ค์ฐจ์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ ์๊ฐํ
๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ): catplot(kind='count')
๋น๋ ๋ง๋๊ทธ๋ํ(๋ค์ค, ๋์ ): countplot
์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ: barplot
์์ฝ ํต๊ณ๊ฐ ํฌ์ธํธ๊ทธ๋ํ: pointplot
์์๊ทธ๋ฆผ: boxplot, boxenplot, violinplot
๋ค์ฐจ์ ์์นํ ๋ฐ์ดํฐ ์๊ฐํ
์ ๊ทธ๋ํ(dot plot): stripplot, swarmplot
์ ๋ถ๊ทธ๋ํ(rug plot): rugplot
ํ์คํ ๊ทธ๋จ(histogram): histplot
๋ฐ๋๊ทธ๋ฆผ(density plot): kdeplot
๊ฒฝํ์ ๋์ ๋ถํฌํจ์(empirical cumulative distribution function): ecdfplot
๋ค์ฐจ์ ๋ฐ์ดํฐ ๊ด๊ณ ์๊ฐํ
์ ๊ทธ๋ํ(line plot): lineplot
์ฐ์ ๋(scatter plot): scatterplot
๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋(joint/marginal distribution plot): jointplot
์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix): pairplot
์๊ด ํ๋ ฌ(correlation matrix): heatmap, clustermap
ํ๊ท ๊ทธ๋ํ(regression plot): regplot, lmplot, residplot
Seaborn ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ ๋ก๋๋งตย
์ค๋น
์ค์ต์ ์ํด์๋ ๊ฐ๋ฐ ํ๊ฒฝ(development environments)๊ณผ ๋ฐ์ดํฐ๊ฐ ํ์ํฉ๋๋ค. ๋จผ์ ๊ฐ๋ฐ ํ๊ฒฝ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
๊ธฐ๋ณธ ํ๊ฒฝ ์ค์
๊ธ์์๋ ๊ฐ๋ฐ ํ๊ฒฝ์ผ๋ก ์ฃผํผํฐ ๋
ธํธ๋ถ(Jupyter notebook)์ ์ฌ์ฉํ์ต๋๋ค. ์ฌ๊ธฐ์๋ ์๊ฐํ ์ค์ต์ ํ๋๋ฐ ํ์ํ ์ต์ํ์ ์ค์ ๋ง ์ ์ฉํ๊ฒ ์ต๋๋ค. ์ฝ๋๋ณ ์์ธํ ์ค๋ช
์ Matplotlib ์ฌ์ฉ๋ฒ(์์ )์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฃผํผํฐ ๋
ธํธ๋ถ์ ์์ธํ ํ๊ฒฝ์ค์ ๋ฐฉ๋ฒ์
์ฃผํผํฐ ๋
ธํธ๋ถ ํ๊ฒฝ ์ค์ ํ๊ธฐ
๋ฅผ ์ฐธ์กฐํ์๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
import
numpy
as
np
import
pandas
as
pd
import
matplotlib
.
pyplot
as
plt
from
matplotlib
import
rcParams
import
seaborn
as
sns
import
warnings
def
setting_styles_basic
(
)
:
rcParams
[
'font.family'
]
=
'Malgun Gothic'
rcParams
[
'axes.unicode_minus'
]
=
False
setting_styles_basic
(
)
warnings
.
filterwarnings
(
'ignore'
)
๋ค์์ผ๋ก๋ ๊ทธ๋ํ์ ์ค์ผ์ผ(scale)์ ์กฐ์ ํ๊ฒ ์ต๋๋ค. ์ค์ผ์ผ ์กฐ์ ์
sns.set_context
ํจ์๋ฅผ ์ด์ฉํด ์ค์ ํ ์ ์์ต๋๋ค. Seaborn์ ๋ค์ํ ์คํ์ผ๋ง ๋ฐฉ๋ฒ์
ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ
์ ์คํ์ผ๋ง ๋ถ๋ถ์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฝ๋ ์คํ ๊ฒฐ๊ณผ๋ ๊ทธ๋ํ ์ ์ญ์ ์ ์ฉ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
set_context
(
'paper'
,
rc
=
{
'font.size'
:
15
,
'xtick.labelsize'
:
15
,
'ytick.labelsize'
:
15
,
'axes.labelsize'
:
15
}
)
์ค์ต์ ์ํ ๊ธฐ๋ณธ์ ์ธ ํ๊ฒฝ ์ค์ ์ ๋ง์ณค๋ค๋ฉด ๋ค์์ ๋ฐ์ดํฐ๋ฅผ ์ค๋นํ ์ฐจ๋ก์
๋๋ค.
๋ฐ์ดํฐ
์ค์ต์ ์ํด์ Seaborn์ ๋ด์ฅ ๋ฐ์ดํฐ๋ฅผ
load_dataset()
ํจ์๋ฅผ ์ด์ฉํด ๋ก๋ฉํด ์ค๊ฒ ์ต๋๋ค. ํน์ ๋ฐ์ดํฐ์
์ Sklearn(์ฌ์ดํท๋ฐ)์์ ๋ถ๋ฌ์ pandas์ DataFrame์ผ๋ก ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค. ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
df_titanic
=
sns
.
load_dataset
(
'titanic'
)
df_iris
=
sns
.
load_dataset
(
'iris'
)
df_penguins
=
sns
.
load_dataset
(
'penguins'
)
df_tips
=
sns
.
load_dataset
(
'tips'
)
df_diamonds
=
sns
.
load_dataset
(
'diamonds'
)
df_planets
=
sns
.
load_dataset
(
'planets'
)
df_flights
=
sns
.
load_dataset
(
'flights'
)
from
sklearn
.
datasets
import
load_wine
wine_data
=
load_wine
(
)
df_wines
=
pd
.
DataFrame
(
data
=
wine_data
.
data
,
columns
=
wine_data
.
feature_names
)
๊ทธ๋ผ ์ง๊ธ๋ถํฐ ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ ๋ณ๋์ด 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ์ ๋ณ๋์ด 3๊ฐ ์ด์์ธ ๋ฐ์ดํฐ๋ฅผ ํฌํจํฉ๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋ํ๋ก ํํํ ๋๋ ์์์ผ๋ก ๊ตฌ๋ถํ๋
hue
, ์บ๋ฒ์ค๋ก ๊ตฌ๋ถํ๋
col
, ์ ํฌ๊ธฐ๋ก ๊ตฌ๋ถํ๋
size
๋ฑ์ ํ๋ผ๋ฏธํฐ๋ฅผ ์ด์ฉํด ์๊ฐํ ์ฐจ์์ ๋ํ๋๊ฐ ์ ์์ต๋๋ค. ๋จผ์ ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค.
๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ๋ฒ์ฃผํ
๋ค๋ณ๋ ๋ฒ์ฃผํ ์๋ฃ๋ฅผ ์๊ฐํํ๋ Seaborn์ ๊ทธ๋ํ๋ ๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ, ๋ค์ค, ๋์ )๊ฐ ์์ต๋๋ค.
1) ๋น๋ ๋ง๋๊ทธ๋ํ: countplot()
๋น๋ ๋ง๋๊ทธ๋ํ(์นด์ดํธํ๋กฏ)์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ์ ๊ฐ์๋ฅผ ํํํฉ๋๋ค.
๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ
๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ ๋ ๋ณ๋์ ๋ํ ๋น๋ ๋ง๋๊ทธ๋ํ 2๊ฐ๋ฅผ ๊ฐ๊ฐ์ ์บ๋ฒ์ค(canvas)์ ๋ณ๋ ฌ๋ก ๋์ดํ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
catplot()
ํจ์์
kind='count'
์
col
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
countplot()
ํจ์๋ก๋ ๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
python
sns
.
catplot
(
x
=
'class'
,
col
=
'who'
,
kind
=
'count'
,
data
=
df_titanic
)
countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํย
๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋
countplot()
๋๋
catplot()
์
hue
ํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
hue
์ต์
์ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํ๋ ํ๋ผ๋ฏธํฐ์
๋๋ค. ๋จผ์ ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ถํฐ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
countplot()
ํจ์ ๋๋
caplot()
ํจ์๋ก ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด ํด๋น ํจ์์
x
ํ๋ผ๋ฏธํฐ์ ๊ฐ๋ก์ถ ๋ฒ์ฃผ๋ก ์ฌ์ฉํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๊ณ ,
hue
ํ๋ผ๋ฏธํฐ์ ๋ค๋ฅธ ์์์ผ๋ก ๊ตฌ๋ถํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
countplot
(
x
=
'class'
,
hue
=
'who'
,
data
=
df_titanic
)
sns
.
catplot
(
x
=
'class'
,
hue
=
'who'
,
kind
=
'count'
,
palette
=
'pastel'
,
edgecolor
=
'.6'
,
data
=
df_titanic
)
countplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํย
histplot()
ํจ์์
multiple='dodge'
์ต์
์ ์ฃผ์ด๋ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
histplot()
ํจ์๋ ์์นํ ์๋ฃ๋ฅผ ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ง๋ค ๋ ์ฌ์ฉํ๋ ํจ์์ด์ง๋ง, ํ์คํ ๊ทธ๋จ์ ๋ง๋ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ์ฃผ๊ณ x์ถ ๋๊ธ์ ์์ ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ผ๋ฐ ๋ง๋๊ทธ๋ํ์ฒ๋ผ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
ax
=
sns
.
histplot
(
x
=
'sex'
,
hue
=
'survived'
,
multiple
=
'dodge'
,
shrink
=
.8
,
data
=
df_titanic
)
ax
.
tick_params
(
bottom
=
False
)
histplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํย
์ด๋ฒ์๋ ์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
์ํ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ๋ ์ฌ์ฉํ ํจ์์
x
ํ๋ผ๋ฏธํฐ ๋์
y
ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
countplot
(
y
=
'class'
,
hue
=
'who'
,
data
=
df_titanic
)
sns
.
catplot
(
y
=
'class'
,
hue
=
'who'
,
kind
=
'count'
,
palette
=
'pastel'
,
edgecolor
=
'.6'
,
data
=
df_titanic
)
countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ฐ๋ก ๊ทธ๋ฃนํ ๋ง๋๊ทธ๋ํย
๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
Seaborn์ผ๋ก ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๋ง๋ค๋ ค๋ฉด
histplot()
ํจ์์
multiple='stack'
์ต์
์ ์ฃผ๋ฉด ๋ฉ๋๋ค.
์์ง ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
python
ax
=
sns
.
histplot
(
x
=
'sex'
,
hue
=
'survived'
,
multiple
=
'stack'
,
shrink
=
.8
,
data
=
df_titanic
)
ax
.
tick_params
(
bottom
=
False
)
histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์์ง ๋์ ๋ง๋๊ทธ๋ํย
์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
x
ํ๋ผ๋ฏธํฐ ๋์
y
ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
python
ax
=
sns
.
histplot
(
y
=
'sex'
,
hue
=
'survived'
,
multiple
=
'stack'
,
shrink
=
.8
,
palette
=
'pastel'
,
data
=
df_titanic
)
;
ax
.
tick_params
(
left
=
False
)
histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์ํ ๋์ ๋ง๋๊ทธ๋ํย
2) ์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ: barplot()
์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ๋ ๋ฒ์ฃผํ ์๋ฃ์ ๋ํ ์์นํ ๋ฐ์ดํฐ๋ฅผ ๋ถํธ์คํธ๋ฉ ์ํ๋ง(์๋ณธ ๋ฐ์ดํฐ์ ๋์ผํ ํฌ๊ธฐ์ ์ํ์ ์ฌ๋ฌ ๋ฒ ๋ณต์ ์ถ์ถ)ํ์ฌ ์ป์ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ ๊ทธ ํ๊ท ์ ์ ๋ขฐ๊ตฌ๊ฐ(confidence interval)์ ๋ํ๋ธ ๋ง๋๊ทธ๋ํ์
๋๋ค. ์ ๋ขฐ๊ตฌ๊ฐ์ ๋ง๋ ์ ๊ฒ์ ์ ์ค์ฐจ ๋ง๋(error bar)๋ก ํํ๋ฉ๋๋ค. ์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
barplot()
ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
catplot()
ํจ์์
kind='bar'
์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก๋ ๋ณต์ ์ํ๋ง๋ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ 95% ์ ๋ขฐ๊ตฌ๊ฐ์ด ํํ๋์ง๋ง
estimator
ํ๋ผ๋ฏธํฐ์
ci
ํ๋ผ๋ฏธํฐ๋ก ๊ฐ๊ฐ ์์ฝ ํต๊ณ๊ฐ๊ณผ ์ ๋ขฐ๊ตฌ๊ฐ์ ์ง์ ํ ์ ์์ต๋๋ค. ์ต์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
estimator: ์ค์๊ฐ
np.median
, ํฉ๊ณ
np.sum
๋ฑ
ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95),
sd
๋ก ์ค์ ์ ํ์คํธ์ฐจ(standard deviation)๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ,
None
์ผ๋ก ์ค์ ์ ์ค์ฐจ ๋ง๋ ์ ๊ฑฐ
n_boot: ๋ถํธ์คํธ๋ฉ ์ํ๋ง ํ์(๊ธฐ๋ณธ๊ฐ: 1000)
๋จผ์ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๋ฒ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
๊ธฐ๋ณธ
์์ง ์์ฝ ๋ง๋๊ทธ๋ํ
์์ง ํ๊ท ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
barplot
(
x
=
'day'
,
y
=
'total_bill'
,
data
=
df_tips
)
sns
.
catplot
(
x
=
'day'
,
y
=
'total_bill'
,
kind
=
'bar'
,
data
=
df_tips
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํย
์ํ ์์ฝ ๋ง๋๊ทธ๋ํ
๋ง์ผ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
barplot()
ํจ์์
orient='h'
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
barplot
(
x
=
'total_bill'
,
y
=
'day'
,
orient
=
'h'
,
data
=
df_tips
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ง๋๊ทธ๋ํย
๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
barplot()
ํจ์์
hue
ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ๋ฉด ์์์ผ๋ก ๊ตฌ๋ถ๋๋ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
๋ค์์ ๋ณ๋์ด 3๊ฐ์ธ ๋ฐ์ดํฐ๋ฅผ ์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ก ํํํ๋ ์์ ์ฝ๋์
๋๋ค.
python
sns
.
barplot
(
x
=
'day'
,
y
=
'total_bill'
,
hue
=
'smoker'
,
data
=
df_tips
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํย
์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ผ๋ฉด
orient=h
ํ๋ผ๋ฏธํฐ๊ฐ์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
barplot
(
x
=
'total_bill'
,
y
=
'day'
,
hue
=
'smoker'
,
orient
=
'h'
,
data
=
df_tips
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํย
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
barplot()
ํจ์์
dodge=False
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. Seaborn์์ ๋์ ๋ง๋๊ทธ๋ํ๋ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋์ ์ต๋๊ฐ ์์ ๋ค๋ฅธ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋๋ฅผ ์์์ ๋ง๋๋ ๊ฒ์ด ์๋๋ผ ๊ทธ๋ํ ์์ฒด๋ฅผ ์๋ก ๊ฒน์ณ์ ๊ทธ๋ฆฐ ๊ฒ์
๋๋ค.
python
sns
.
barplot
(
x
=
'day'
,
y
=
'total_bill'
,
hue
=
'smoker'
,
dodge
=
False
,
data
=
df_tips
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ1ย
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋
barplot()
ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํด์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
python
s1
=
sns
.
barplot
(
x
=
'species'
,
y
=
'sepal_length'
,
color
=
'coral'
,
ci
=
None
,
data
=
df_iris
)
s2
=
sns
.
barplot
(
x
=
'species'
,
y
=
'petal_length'
,
color
=
'powderblue'
,
ci
=
None
,
data
=
df_iris
)
barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ2ย
์ ๊ทธ๋ํ์์ ๋ง๋์ y์ถ๊ฐ(์์น ๋ ๋ถ๋ถ)์ ๊ฐ๊ฐ
sepal_length
์ ํ๊ท ๊ณผ
petal_length
์ ํ๊ท ์ ๋ํ๋
๋๋ค.
3) ํฌ์ธํธ ํ๋กฏ: pointplot()
ํฌ์ธํธํ๋กฏ์ ๋ง๋๊ทธ๋ํ์ ๋์ผํ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋์ ํ๊ท ๊ฐ์ ๋ง๋ ๋์ ์ (point)์ผ๋ก ํํํฉ๋๋ค. ํฌ์ธํธํ๋กฏ์
pointplot()
ํจ์๋ฅผ ์ฌ์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ํฌ์ธํธํ๋กฏ์ ํ ํ๋ฉด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๋น๊ตํ ๋ ์ ์ฉํฉ๋๋ค.
python
sns
.
pointplot
(
x
=
'day'
,
y
=
'total_bill'
,
data
=
df_tips
)
sns
.
catplot
(
x
=
'day'
,
y
=
'total_bill'
,
kind
=
'point'
,
data
=
df_tips
)
pointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํฌ์ธํธ ํ๋กฏย
๋ง์ผ ์ ๋ขฐ๊ตฌ๊ฐ์ด ์๋๋ผ ํ์คํธ์ฐจ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด
ci='sd'
๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ ๊ณผ ํฌ์ธํธ๋ฅผ ๋ค๋ฅธ ๋ชจ์์ผ๋ก ํํํ ์๋ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
pointplot
(
x
=
'class'
,
y
=
'survived'
,
hue
=
'sex'
,
palette
=
{
'male'
:
'g'
,
'female'
:
'm'
}
,
markers
=
[
'^'
,
'o'
]
,
linestyles
=
[
'-'
,
'--'
]
,
data
=
df_titanic
)
์ต์
์ ์ถ๊ฐํ ํฌ์ธํธ ํ๋กฏย
4) ์์๊ทธ๋ฆผ: boxplot(), boxenplot(), violinplot()
์์๊ทธ๋ฆผ(๋ฐ์คํ๋กฏ)์ ๋ฐ์ดํฐ์ ๋ถ์๋ฅผ 5๊ฐ์ง ์์ฝ ์์น(five-number summary)๋ก ์ ๊ณตํ๋ ๋ํ์
๋๋ค.
์ 3์ฌ๋ถ์์ (Q3): ์ ์ฒด ๋ฐ์ดํฐ ์ค ์์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
์ 2์ฌ๋ถ์์ (Q2 ๋๋ ์ค์๊ฐ): ์ ์ฒด ๋ฐ์ดํฐ์ 50%์ ํด๋นํ๋ ๊ฐ(์ค์๊ฐ), ๋ฐ์ค ๋ด๋ถ์ ์ ์ผ๋ก ํ์
์ 1์ฌ๋ถ์์ (Q1): ์ ์ฒด ๋ฐ์ดํฐ ์ค ํ์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์๋์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
์ฌ๋ถ์ ๋ฒ์ (IQR): Q3 - Q1, ๋ฐ์ค์ ๋์ด๋ก ํํ
์ต๋๊ฐ (Maximum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ํฐ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
์ต์๊ฐ (Minimum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ์์ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์๋์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
์ด์์น (Outliers): ์ผ๋ฐ์ ์ผ๋ก Q1 - 1.5IQR ๋ฏธ๋ง์ด๊ฑฐ๋ Q3 + 1.5IQR ์ด๊ณผ์ธ ๊ฐ๋ค์ ๊ฐ๋ณ ์ ์ผ๋ก ํ์
๊ธฐ๋ณธ
Seaborn์์ ์์๊ทธ๋ฆผ์ ๋ง๋ค๋ ค๋ฉด
boxplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
catplot()
ํจ์์ 'kind='box'` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
python
sns
.
boxplot
(
data
=
df_iris
)
sns
.
catplot
(
data
=
df_iris
,
kind
=
'box'
)
boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ง ์์๊ทธ๋ฆผย
๋ง์ผ ์์๊ทธ๋ฆผ์ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
orient='h'
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
boxplot
(
data
=
df_iris
,
orient
=
'h'
)
boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผย
3์ฐจ์ ๋ฐ์คํ๋กฏ์
hue
์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
hue
ํ๋ผ๋ฏธํฐ๋ฅผ ๋ํ๋ฉด ๋น์ทํ ์์ฑ์ ๋ฐ์ดํฐ๋ผ๋ฆฌ ๋ถ๋ฅํ ์ ์์ต๋๋ค.
python
df_tips
[
'weekend'
]
=
df_tips
[
'day'
]
.
isin
(
[
'Sat'
,
'Sun'
]
)
sns
.
boxplot
(
x
=
'total_bill'
,
y
=
'day'
,
hue
=
'weekend'
,
orient
=
'h'
,
dodge
=
False
,
data
=
df_tips
)
boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผ2ย
๋ฐ์จ ํ๋กฏ
๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ฌ ๊ฐ์ ๋ถ์๋ก ๋๋ ๋ฐ์คํ๋กฏ์
๋๋ค. ๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ์
์ ๋ ๋ง์ ๋ถ์์(quantiles)๋ก ๋๋์ด ๊ธฐ์กด์ ์์๊ทธ๋ฆผ๋ณด๋ค ์ด์์น(outliers)์ ๋ํด ๋ ๋ง์ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ฐ๋ผ์, ๋ฐ์จ ํ๋กฏ์ ํฐ ๋ฐ์ดํฐ์
์ ์ฒ๋ฆฌํ๊ธฐ์ ์ ํฉํฉ๋๋ค.
๋ฐ์จ ํ๋กฏ์ ๋ง๋ค๋ ค๋ฉด
boxenplot()
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
catplot()
ํจ์์
kind='boxen'
์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
python
sns
.
boxenplot
(
x
=
'color'
,
y
=
'price'
,
data
=
df_diamonds
.
sort_values
(
'color'
)
)
sns
.
catplot
(
x
=
'color'
,
y
=
'price'
,
kind
=
'boxen'
,
data
=
df_diamonds
.
sort_values
(
'color'
)
)
boxenplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์จ ํ๋กฏย
๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ
๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ์์๊ทธ๋ฆผ๊ณผ KDE ๋ฐฉ๋ฒ์ ์ด์ฉํด ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์(์ปค๋๋ฐ๋์ถ์ ํจ์)๋ฅผ ํฉ์น ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
violinplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
catplot()
ํจ์์
kind='violin'
์ต์
์ ์ถ๊ฐํด๋ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
python
sns
.
violinplot
(
x
=
'total_bill'
,
y
=
'day'
,
data
=
df_tips
)
sns
.
catplot
(
x
=
'total_bill'
,
y
=
'day'
,
kind
=
'violin'
,
data
=
df_tips
)
violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏย
์ด์ง ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด
hue
์
split=True
ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ2ย
5) ๋ชจ์์ดํฌ ๊ทธ๋ํ
๋ง๋๊ทธ๋ํ ์ธ์๋ ๋ณ๋์ด ๋ชจ๋ ๋ฒ์ฃผํ์ธ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋ ๋ชจ์์ดํฌ ๊ทธ๋ํ(mosaic plot)๋ฅผ ์ฌ์ฉํ๊ธฐ๋ ํฉ๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๊ทธ๋ฃน ๋ด์ ๋ฐ์ดํฐ ๋ฐฑ๋ถ์จ์ ๋ณด์ฌ์ฃผ๋ ๋์ ๋ง๋๊ทธ๋ํ์
๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๋ณ์๊ฐ 3๊ฐ ์ด์์ผ ๋๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ชจ์์ดํฌ ๊ทธ๋ํ๋
statmodels.graphics.mosaic
ํจํค์ง์
mosaic()
ํจ์๋ฅผ ์ด์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
from
statsmodels
.
graphics
.
mosaicplot
import
mosaic
import
matplotlib
.
pyplot
as
plt
props
=
lambda
key
:
{
'color'
:
'teal'
if
'1'
in
key
else
'lightgray'
}
labelizer
=
lambda
k
:
{
(
'female'
,
'1'
)
:
'์ฌ์ฑ\n(์์กด)'
,
(
'female'
,
'0'
)
:
'์ฌ์ฑ\n(์ฌ๋ง)'
,
(
'male'
,
'1'
)
:
'๋จ์ฑ\n(์์กด)'
,
(
'male'
,
'0'
)
:
'๋จ์ฑ\n(์ฌ๋ง)'
}
[
k
]
mosaic
(
df_titanic
.
sort_values
(
'sex'
)
,
[
'sex'
,
'survived'
]
,
properties
=
props
,
labelizer
=
labelizer
,
axes_label
=
False
)
plt
.
title
(
'ํ์ดํ๋ํธ ์ฑ๋ณ ์์กด์'
,
fontsize
=
17
)
mosaic ํจ์๋ก ๊ทธ๋ฆฐ ๋ชจ์์ดํฌ ํ๋กฏย
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ์๋ ๋ค๋ณ๋ ์์นํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ์์นํ
1) ์ ๊ทธ๋ํ: stripplot(), swarmplot()
์ ๊ทธ๋ํ๋ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ผ๋ก ๋ํ๋ธ ๋ํ์
๋๋ค. ์ ๊ทธ๋ํ๋ฅผ ์ด์ฉํ๋ฉด ๋ฐ์ดํฐ์ ์ค์ ์์น์ ๋ถํฌ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ต๋๋ค. Seaborn์์ ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ํจ์๋
stripplot()
์
๋๋ค.
stripplot
python
sns
.
stripplot
(
data
=
df_tips
)
sns
.
catplot
(
kind
=
'strip'
,
data
=
df_tips
)
stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํย
stripplot()
ํจ์์
jitter
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ผ๋ ฌ๋ก ๊ทธ๋ฆด ์ ์์ต๋๋ค.
jitter: ์งํฐ(jitter)๋ ๋ฐ์ดํฐ ๊ฐ์ ์ฝ๊ฐ์ ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ, ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐ ๊ฐ์ด ์กฐ๊ธ์ฉ ์์ง์ฌ์ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ ๋ฐ์ดํฐ๊ฐ ๊ทธ๋ํ์ ์ฌ๋ฌ ๋ฒ ๊ฒน์ณ์ ํ์๋๋ ํ์์ ๋ง์์ค
python
sns
.
stripplot
(
x
=
'total_bill'
,
y
=
'smoker'
,
jitter
=
False
,
data
=
df_tips
)
stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ2ย
๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์๋ก ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์งํ๋ ค๋ฉด
dodge=True
์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
dodge=True: hue๋ก ๊ตฌ๋ถ๋ ๊ทธ๋ฃน ์ฌ์ด ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ๋ฐ์ดํฐ๊ฐ ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์ง
python
sns
.
stripplot
(
x
=
'tip'
,
y
=
'day'
,
palette
=
'Spectral'
,
dodge
=
True
,
data
=
df_tips
)
stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ3ย
dodge=True
์ต์
์ฒ๋ผ ์ ๊ทธ๋ํ์์ ๋ฐ์ดํฐ ํฌ์ธํธ๋ค์ด ์๋ก ๊ฒน์น์ง ์๊ณ ์์ ๋ฌด๋ฆฌ์ฒ๋ผ ๋ณด์ด๊ฒ ๊ทธ๋ํ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค. ์ด๋ ์ฌ์ฉํ๋ ํจ์๊ฐ
swarmplot()
์
๋๋ค.
swarmplot
swarmplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ์ ๋ํ์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ผ(swarm)์ฒ๋ผ ๋ฌด๋ฆฌ๋ฅผ ๋ง๋ค์ด ๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์ค์ฒฉ๋๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค. ๋ผ ํ๋กฏ์ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
swarmplot
(
data
=
df_tips
)
sns
.
catplot
(
kind
=
'swarm'
,
data
=
df_tips
)
swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ์ ์ฒด ๋ณ์ย
x
์
y
ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ ๋ณ์์ ๋ํ ๋ผ ํ๋กฏ์ ๋ง๋ค ์ ์์ต๋๋ค.
python
sns
.
swarmplot
(
x
=
'day'
,
y
=
'total_bill'
,
data
=
df_tips
)
sns
.
catplot
(
x
=
'day'
,
y
=
'total_bill'
,
kind
=
'swarm'
,
data
=
df_tips
)
swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ํน์ ๋ณ์ย
์ค์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ด ์๋๋ผ ์ ๋ถ(rug)์ผ๋ก ํํํ ์๋ ์์ต๋๋ค.
2) ์ ๋ถ๊ทธ๋ํ: rugplot()
์ค์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ์ ๋ถ์ผ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด
rugplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
rugplot()
์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๊ฐ ์ถ ์์ ๋ณด์ฌ์ค๋๋ค.
python
sns
.
rugplot
(
x
=
'total_bill'
,
y
=
'tips'
,
data
=
'df_tips'
)
rugplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ถ๊ทธ๋ํย
๋ณดํต ์ ๋ถ๊ทธ๋ํ๋ ๋ค๋ฅธ ๊ทธ๋ํ์ ํจ๊ป ๊ทธ๋ฆฝ๋๋ค. ๊ทธ๋ํ๋ฅผ ๊ฒน์ณ ๊ทธ๋ฆฌ๋ ค๋ฉด ๊ทธ๋ํ ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
scatterplot
(
x
=
'total_bill'
,
y
=
'tip'
,
data
=
df_tips
)
sns
.
rugplot
(
x
=
'total_bill'
,
y
=
'tip'
,
data
=
df_tips
)
rugplot() ํจ์์ scatterplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํย
3) ํ์คํ ๊ทธ๋จ: histplot()
Seaborn์์ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ํจ์๋
histplot()
์
๋๋ค.
displot()
ํจ์๋ฅผ ์ด์ฉํด๋ ๋ฉ๋๋ค. Seaborn์์
histplot()
ํจ์๋ก ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ(bivariate histogram)์ ๊ทธ๋ฆด ๋๋ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํฉ๋๋ค. ์ฌ๊ธฐ์๋
histplot()
๋์
displot()
์ ์ด์ฉํด ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ
python
sns
.
histplot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
data
=
df_penguins
)
์ต์
์ ์ด์ฉํ๋ฉด ๋ค์ํ ์ข
๋ฅ์ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
hue: ๊ทธ๋ฃน๋ณ ํ์คํ ๊ทธ๋จ
multiple='stack': ๋์ ํ์คํ ๊ทธ๋จ(ํฌ๊ฐ์ง ์๊ณ ์๊ธฐ)
multiple='dodge': ๋ค์ค ํ์คํ ๊ทธ๋จ
python
sns
.
displot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
element
=
'step'
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
multiple
=
'stack'
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'flipper_length_mm'
,
hue
=
'sex'
,
multiple
=
'dodge'
,
data
=
df_penguins
)
displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ํ์คํ ๊ทธ๋จ1ย
python
sns
.
displot
(
x
=
'bill_length_mm'
,
y
=
'species'
,
hue
=
'species'
,
legend
=
False
,
data
=
df_penguins
)
displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ2ย
log_scale=True: x์ถ ๊ฐ ๋ก๊ทธ ์ค์ผ์ผ๋ก ๋ณํ
element='poly': ๊ทธ๋ํ๋ฅผ ๋ถํฌ๋ค๊ฐํ(distribution polygon)์ผ๋ก ์ง์
fill=False: ๊ทธ๋ํ ์ ์๋ ์๊น ์ฑ์ฐ์ง ์๊ธฐ
python
sns
.
displot
(
x
=
'distance'
,
hue
=
'method'
,
log_scale
=
True
,
element
=
'poly'
,
fill
=
False
,
data
=
df_planets
)
displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ3ย
ํ ์บ๋ฒ์ค ๋ด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ์ง ์๊ณ ๊ทธ๋ํ๋ฅผ ์๋ก ๋ค๋ฅธ ์บ๋ฒ์ค์ ๋๋์ด์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
col
์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
col
์ต์
์ ๊ทธ๋ํ๋ฅผ ๊ฐ๋ณ ์บ๋ฒ์ค์ ๋๋์ด ๊ทธ๋ ค์ค๋๋ค.
python
sns
.
displot
(
x
=
'flipper_length_mm'
,
col
=
'sex'
,
data
=
df_penguins
)
displot ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ4ย
๋ง์ผ ๋ ๋ณ๋์ด ๋ชจ๋ ์์นํ์ด๋ผ๋ฉด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ์ ํํธ๋งต(heatmap) ๊ฐ์ ๋ชจ์์ ๋ ๊ฒ ๋ฉ๋๋ค.
binwidth: ์ง์ฌ๊ฐํ ํฌ๊ธฐ ์ง์
cbar: ์ ์ง์ค๋์ ๋ฐ๋ฅธ ๋น๋์๋ฅผ ๋ํ๋ด๋ ์ปฌ๋ฌ๋ฐ ์ ๋ฌด ์ง์
hue: ์์ผ๋ก ๊ตฌ๋ถ๋๋ ๊ทธ๋ฃน๋ณ ๊ทธ๋ํ ์ค์ (๋ถํฌ ๊ฐ ์ค๋ณต๋๋ ๋ถ๋ถ์ด ์ ์ด์ผ ํจ)
python
sns
.
displot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
binwidth
=
(
2
,
.5
)
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
cbar
=
True
,
data
=
df_penguins
)
sns
.
displot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
hue
=
'species'
,
data
=
df_penguins
)
displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค๋ณ๋ ํ์คํ ๊ทธ๋จย
bins: ๋ฑ๊ธ ์ ์ง์ ํ๊ธฐ
discrete: x์ถ ๋ผ๋ฒจ์ ๋ง๋ ์ค๊ฐ์ ์์น์ํค๊ธฐ(True)
pthresh: ์ ์ฒด ๋ฐ์ดํฐ ์ค์์ ํด๋น ๋น์จ(0~1)์ ์
ํฌ๋ช
์ฒ๋ฆฌํ๊ธฐ
pmax: ํฌํ๋ ์ต๋๊ฐ(0~1) ์ง์ ํ๊ธฐ
python
sns
.
displot
(
df_planets
,
x
=
'year'
,
y
=
'distance'
,
bins
=
30
,
discrete
=
(
True
,
False
)
,
log_scale
=
(
False
,
True
)
)
sns
.
displot
(
df_planets
,
x
=
'year'
,
y
=
'distance'
,
bins
=
30
,
discrete
=
(
True
,
False
)
,
log_scale
=
(
False
,
True
)
,
thresh
=
None
)
sns
.
displot
(
df_planets
,
x
=
'year'
,
y
=
'distance'
,
bins
=
30
,
discrete
=
(
True
,
False
)
,
log_scale
=
(
False
,
True
)
,
pthresh
=
.05
,
pmax
=
.9
)
sns
.
displot
(
df_planets
,
x
=
'year'
,
y
=
'distance'
,
bins
=
30
,
discrete
=
(
True
,
False
)
,
log_scale
=
(
False
,
True
)
,
cbar
=
True
,
cbar_kws
=
dict
(
shrink
=
.75
)
)
displot() ํจ์์ ๋ค์ํ ์ต์
์ ์ ์ฉํ ํ์คํ ๊ทธ๋จ6ย
์ง๊ธ๊น์ง ์ฌ๋ฌ ๊ฐ์ง ์ต์
์ ์ด์ฉํด ๋ค์ํ ์ข
๋ฅ์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ ค๋ณด์์ต๋๋ค. ๋ง์ผ ๊ทธ๋ฃน๋ณ๋ก ๊ด์ธก์๊ฐ ๋ค๋ฅธ ํ์คํ ๊ทธ๋จ์ ๋น๊ตํ๊ณ ์ถ๋ค๋ฉด, ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ์ ๊ทํ(normalization)ํ๋ฉด ๋ฉ๋๋ค.
์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ(data point)๊ฐ ๋์ผํ ์ ๋์ ์ค์ผ์ผ(์ค์๋)๋ก ํด์๋๋๋ก ๋ง๋๋ ๊ณผ์ ์
๋๋ค. ์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ์ ์ค์๋๋ฅผ ๊ท ๋ฑํ๊ฒ ๋ง๋ญ๋๋ค. ๋ฐ๋ผ์, ์ด์์น๋ฅผ ์ง๋ ํน์ ์์ฑ์ด ์ ์ฒด ์์ฑ์ฒ๋ผ ๋ํ๋๋ ์ผ๋ฐํ์ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ ์ ์์ต๋๋ค. ์ ๊ทํ๋ฅผ ๊ฑฐ์น ํ์คํ ๊ทธ๋จ์ ์ ๊ท ํ์คํ ๊ทธ๋จ(normalized histogram)์ด ๋ฉ๋๋ค.
์ ๊ทํ๋ฅผ ์ํ ์ค์ผ์ผ๋ง ๊ธฐ์ค์ ์ผ๋ก๋ ์ ์ฒด ๊ด์ธก์์ ๋ฉด์ ์ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋จผ์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค.
์ ๊ท ํ์คํ ๊ทธ๋จ(์ ์ฒด ๊ด์ธก์)
Seaborn์์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด
histplot()
ํจ์ ๋๋
displot()
ํจ์์
stat='probability'
๋๋
stat='percent'
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
stat
์ต์
์
probability
์ธ์๋ฅผ ์ฃผ๋ฉด y์ถ์ด ํ๋ฅ (probability)์ธ ๊ทธ๋ํ๊ฐ ๊ทธ๋ ค์ง๋๋ค. ๋ฐ๋ฉด,
percent
์ต์
์ ์ฌ์ฉํ๋ฉด y์ถ์ด ๋ฐฑ๋ถ์จ(percent)์ธ ๊ทธ๋ํ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ์ ์์ ๊ฒฝ์ฐ ๋ง๋๋ค์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ๋ฉด 1์ด ๋๊ณ , ํ์์ ๊ฒฝ์ฐ์๋ 100์ด ๋ฉ๋๋ค. ์ด ์ต์
์ ์ถ๊ฐ๋ฉด ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
histplot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'probability'
,
data
=
df_penguins
)
sns
.
histplot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'percent'
,
data
=
df_penguins
)
์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จย
์ฌ๊ธฐ์
commont_norm
์ต์
์
False
๋ก ์ง์ ํ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๊ฐ๋ณ ๊ทธ๋ฃน์ ๊ด์ธก์๋ก ์ ๊ทํํ ์ ์์ต๋๋ค. ์ด๋ ๋ง๋ค์ด์ง๋ ํ์คํ ๊ทธ๋จ์ ์๋ก ๋
๋ฆฝ์ ์
๋๋ค.
python
sns
.
histplot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'probability'
,
common_norm
=
False
,
data
=
df_penguins
)
sns
.
histplot
(
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'percent'
,
common_norm
=
False
,
data
=
df_penguins
)
์ ์ฒด๊ด์ธก์๋ก ์ ๊ทํ: ๊ฐ๋ณ ํ์คํ ๊ทธ๋จย
์ด๋ฒ์๋ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
์ ๊ท ํ์คํ ๊ทธ๋จ(๋ฉด์ )
Seaborn์์ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด
stat='density'
์ต์
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ์ต์
์ ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์น์ ๊ฐ์์ ๋ง๋ ๋๋น(width)์ ๊ณฑ์ผ๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด์ค๋๋ค. ์ด ํ์คํ ๊ทธ๋จ์์ y์ถ์ ๋ฐ๋(density)๊ฐ ๋๊ณ , ๊ฐ ๋ง๋์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ ํฉ์ 1์ด ๋ฉ๋๋ค. ๋ง์ผ, ๋
๋ฆฝ์ ์ธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
common_norms=False
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'density'
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
hue
=
'species'
,
stat
=
'density'
,
common_norm
=
False
)
๋ฉด์ ์ผ๋ก ์ ๊ทํ: ๊ธฐ๋ณธ ์ ๊ท ํ์คํ ๊ทธ๋จ ๋ฐ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จย
์ง๊ธ๊น์ง Seaborn์์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ๊ณผ 2๊ฐ์ง ์ข
๋ฅ์ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ ์ง๊ด์ ์
๋๋ค. ํ์คํ ๊ทธ๋จ์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋น ๋ฅด๊ณ ํ๋์ ํ์
ํ๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ฉด ์ข์ต๋๋ค.
ํ์ง๋ง ํ๊ณ๋ ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ผ๋ก ํ๋ฅ ๋ฐ๋ํจ์(Probability Density Function, PDF)๋ฅผ ๋ํ๋ด๋ฉด ์ ํํ์ง ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์์ ๋ฑ๊ธ์ ์๋ ์๋ฌด๋ฆฌ ๋ง๊ฒ ์ก์๋ ์ ํํ๊ธฐ ๋๋ฌธ์
๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋งค๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ํ์คํ ๊ทธ๋จ์ ๋ฑ๊ธ์ ๋ถ์ฐ์์ ์ด๋ค๋ณด๋ ํ์คํ ๊ทธ๋จ์ ๋ชจ์๋ ๊ณ๋จ๊ณผ ๊ฐ์ด ์ธํ๋ถํํ๊ฒ ๋ํ๋ฉ๋๋ค.
๋ํ, ํ์คํ ๊ทธ๋จ์์๋ ๋ฑ๊ธ์ ๊ฐ๊ฒฉ๊ณผ ๋ฐ์ดํฐ์ ์์ ์์น์ ๋ฐ๋ผ ํ์คํ ๊ทธ๋จ์ ๋ชจ์์ด ๋ฌ๋ผ์ง๋๋ค. ๋ฐ์ดํฐ์ ์ฐจ์(dimension)์ด ์ฆ๊ฐํ ์๋ก ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋ถ์ํ๊ฑฐ๋ ๋ชจ๋ธ์ ์ถ์ ํ๋๋ฐ ํ์ํ ํ๋ณธ ๋ฐ์ดํฐ์ ๊ฐ์๋ ๊ธฐํ๊ธ์์ ์ผ๋ก ์ฆ๊ฐํ๋ค๋ ๋จ์ ๋ ์์ต๋๋ค.
์ด๋ฌํ ํ์คํ ๊ทธ๋จ์ ๋จ์ ์ ๊ฐ์ ํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฐ๋ก ์ปค๋๋ฐ๋์ถ์ (Kernel Density Estimation, KDE)์
๋๋ค. ์ง๊ธ๋ถํฐ๋ ์ปค๋๋ฐ๋์ถ์ ์ด๋ ๋ฌด์์ธ์ง ๊ทธ๋ฆฌ๊ณ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด KDE ๊ณก์ ์ ๊ทธ๋ฆฌ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
4) ์ปค๋๋ฐ๋ํจ์ ๊ทธ๋ํ: kdeplot()
์ปค๋๋ฐ๋์ถ์ ์ด๋ ์ปค๋ ํจ์(kernel function)๋ฅผ ์ด์ฉํด์ ํ๋ฅ ๋ณ์์ ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ์ถ์ ํ๋ ๋น๋ชจ์์ (non-parametric) ํต๊ณ ๋ฐฉ๋ฒ์
๋๋ค. ๋น๋ชจ์์ ๋ฐฉ๋ฒ์ด๋ ๊ด์ธก ๋ฐ์ดํฐ๊ฐ ํน์ ํ๋ฅ ๋ถํฌ๋ฅผ ๋ฐ๋ฅธ๋ค๋ ์ ์ ์์ด ์ค์ํ๋ ๊ฒ์ ๋ฐฉ๋ฒ์
๋๋ค. ์ปค๋ ํจ์๋ ์์ ์ ์ค์ฌ์ผ๋ก ๋์นญ์ ์ด๋ฃจ๊ณ , ์์(non-negative) ์ค์(real-valued)๊ฐ์ ๊ฐ์ง๋ฉฐ, ์ ๋ถ๊ฐ์ด 1์ธ ํจ์(
K
)๋ฅผ ๋ปํฉ๋๋ค. ์ปค๋ ํจ์์๋ ๋ํ์ ์ผ๋ก ๊ฐ์ฐ์์(Gaussian), ์ฝ์ฌ์ธ(cosine), Epanechnikov ํจ์ ๋ฑ์ด ์์ต๋๋ค.
์ปค๋ํจ์ ์ข
๋ฅย
๋ฐ๋๊ทธ๋ฆผ(density plot)์ ์ปค๋ ์ค๋ฌด๋ฉ(kernel smoothing)์ ์ด์ฉํด ์ถ์ ํ ํ์คํ ๊ทธ๋จ์ ํ๋ฅ ๋ฐ๋ํจ์์
๋๋ค. KDE์์๋ ๋ฐ์ดํฐ๋ฅผ ์ปค๋ ํจ์๋ก ๋์นํ์ฌ ํ์คํ ๊ทธ๋จ์์ ๋ํ๋ฌ๋ ๋ฑ๊ธ์ ๋ถ์ฐ์์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค. KDE๋ก ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์
๋๋ค.
๋จ, KDE ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ๋๋ ์กฐ๊ฑด์ด ์์ต๋๋ค. KDE ๋ฐฉ๋ฒ์ ๊ทน๋จ๊ฐ์ด ์๋ ์ฐ์ ์๋ฃ์ ์ฌ์ฉํฉ๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ์ด์์น๊ฐ ์์ผ๋ฉด ํด๋น ๊ฐ์์ ํ๋ฅ ๋ฐ๋ํจ์๊ฐ ๋พฐ์กฑํ ๋ชจ์์ ๋ ๊ฒ ๋๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด์์น๊ฐ ์๋ ์ฐ์ ์๋ฃ์๋ KDE ๋ณด๋ค๋ ํ์คํ ๊ทธ๋จ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ํฉํฉ๋๋ค.
Seaborn์์ KDE ๋ฐฉ๋ฒ์ ํตํด ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
kdeplot()
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
displot()
ํจ์์
kind='kde'
์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ์ด๋ฒ์๋
displot()
ํจ์์
kind='kde'
์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
multiple='stack': ๊ทธ๋ํ ์์์ ๊ทธ๋ฆฌ๊ธฐ
multiple='fill': ๊ฐ ๊ฐ์์ ๊ฒน์น ๋ถํฌ(stacked distribution) ์ ๊ทํํด์ ๊ทธ๋ฆฌ๊ธฐ(๋จ๋ณ๋์ผ ๋๋ง ์ ํจ, ๋ชจ๋ ๊ฐ์์ y์ถ์ ๋ฐ๋๊ฐ 1)
fill=True: ๊ทธ๋ํ ๋ถํฌ๋ช
ํ๊ฒ ๊ทธ๋ฆฌ๊ธฐ
cumulative=True: ๋์ ๋ถํฌํจ์ ๊ทธ๋ฆฌ๊ธฐ
python
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
multiple
=
'stack'
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
multiple
=
'fill'
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
fill
=
True
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
cumulative
=
True
,
common_norm
=
False
,
common_grid
=
True
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
fill
=
True
,
common_norm
=
False
,
palette
=
'crest'
,
alpha
=
.5
,
linewidth
=
0
)
kdeplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๋ฐ๋๊ทธ๋ฆผย
์ด๋ณ๋ KDE ๊ทธ๋ํ๋ ๋ฑ๊ณ ์ (contours)์ผ๋ก ํํ๋ฉ๋๋ค. ๊ฐ ๋ฑ๊ณ ์ ์ ๋ฐ๋๊ฐ ๊ฐ์ ์ง์ (iso-proportions)์ ์ด์ ๊ฒ์
๋๋ค.
thresh: ๊ฐ์ฅ ๋ฎ์ ๋ ๋ฒจ์ ๋ฑ๊ณ ์ ํฌ๊ธฐ ์กฐ์
levels: ๋ฑ๊ณ ์ ๊ฐ์ ๋๋ ๋ชจ์
python
sns
.
displot
(
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'kde'
)
sns
.
displot
(
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'kde'
,
thresh
=
.2
,
levels
=
4
)
sns
.
displot
(
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'kde'
,
levels
=
[
.01
,
.05
,
.1
,
.7
]
)
sns
.
displot
(
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'kde'
,
hue
=
'species'
)
๋ค์ํ ๋ค๋ณ๋ KDE ๋ฑ๊ณ ์ ๊ทธ๋ํย
5) ๊ฒฝํ์ ๋์ ๋ถํฌํจ์: ecdfplot()
๊ฒฝํ์ ๋์ ๋ถํฌํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
ecdfplot()
ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
displot()
ํจ์์ `kind='ecdf' ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
hue_order: # ์ ์์ ์ง์
complementary=True: ์๋ณด ๋์ ๋ถํฌํจ์(complementary cumulative distribution function, CCDF) ๊ทธ๋ฆฌ๊ธฐ
python
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'ecdf'
)
sns
.
displot
(
df_penguins
,
x
=
'flipper_length_mm'
,
kind
=
'ecdf'
,
hue
=
'species'
)
sns
.
displot
(
data
=
df_planets
,
x
=
'distance'
,
hue
=
'method'
,
hue_order
=
[
'Radial Velocity'
,
'Transit'
]
,
log_scale
=
True
,
element
=
'step'
,
fill
=
False
,
cumulative
=
True
,
stat
=
'density'
,
common_norm
=
False
)
sns
.
ecdfplot
(
data
=
df_penguins
,
x
=
'bill_length_mm'
,
hue
=
'species'
,
complementary
=
True
)
ecdfplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๊ฒฝํ์ ๋์ ๋ถํฌํจ์ย
๋ค์ฐจ์ ๋ฐ์ดํฐ: ๊ด๊ณ
1) ์ ๊ทธ๋ํ: lineplot()
์ ๊ทธ๋ํ๋ ์๊ฐ ๊ฒฝ๊ณผ์ ๋ฐ๋ฅธ ์ฐ์ํ ๋ณ์์ ๋ณ๋์ ๋ณด์ฌ์ฃผ๋ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
lineplot()
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
relplot()
ํจ์์
kind='line'
์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ๋ค์์
flights
๋ฐ์ดํฐ์์ ์ฐ๋ณ(x์ถ) ํ๊ท ํ์น๊ฐ ์(y์ถ)๋ฅผ ํํํ ๊ทธ๋ํ์
๋๋ค. ์์์ผ๋ก ํ์๋ ๋ถ๋ถ์ 95% ์ ๋ขฐ๊ตฌ๊ฐ์
๋๋ค.
python
sns
.
lineplot
(
x
=
'year'
,
y
=
'passengers'
,
data
=
df_flights
)
lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ1ย
์ฐ๋ณ(x์ถ) ์ด ํ์น๊ฐ์(y์ถ)๋ฅผ ํํํ๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
python
sns
.
lineplot
(
x
=
'year'
,
y
=
'passengers'
,
data
=
df_flights
.
groupby
(
'year'
)
.
sum
(
)
)
sns
.
relplot
(
x
=
'year'
,
y
=
'passengers'
,
kind
=
'line'
,
data
=
df_flights
.
groupby
(
'year'
)
.
sum
(
)
)
lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ2ย
์๋ณ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด
hue
์
style
์ต์
์ ์ด์ฉํด ๋ฐ์ดํฐ๋ฅผ ์์๊ณผ ์คํ์ผ๋ก ๊ตฌ๋ถํด์ฃผ๋ฉด ๋ฉ๋๋ค.
python
sns
.
lineplot
(
x
=
'year'
,
y
=
'passengers'
,
hue
=
'month'
,
style
=
'month'
,
data
=
df_flights
)
lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ3ย
pandas
์
pivot()
ํจ์๋ฅผ ์ด์ฉํด ๋ง๋ ํ๋ฅผ ์ด์ฉํด๋ ์ ๊ทธ๋ํ์ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
pivot()
ํจ์๋
index
์
columns
ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์ฑ์ ๊ฐ๊ฐ ํ
์ด๋ธ์ ํ๊ณผ ์ด๋ก ์ง์ ํด์
values
ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์น๋ฅผ ํํํฉ๋๋ค.
python
flights_pivot
=
df_flights
.
pivot
(
index
=
'month'
,
columns
=
'year'
,
values
=
'passengers'
)
flights_pivot
pandas์ pivot()ํจ์๋ก ๋ง๋ ์ฐ๋ณ, ์๋ณ ํ์น๊ฐ ํย
2) ์ฐ์ ๋: scatterplot()
์ฐ์ ๋๋ ๋ ๋ฐ์ดํฐ์ ๊ด๊ณ๋ฅผ ์ ์ผ๋ก ํํํ๋ ๋ฐฉ๋ฒ์
๋๋ค. Seaborn์ผ๋ก ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
scatterplot()
ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
relplot()
ํจ์์
kind='scatter'
์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
python
sns
.
scatterplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
data
=
df_penguins
)
sns
.
relplot
(
df_penguins
[
'bill_length_mm'
]
,
df_penguins
[
'bill_depth_mm'
]
,
kind
=
'scatter'
)
Seaborn์ผ๋ก ๊ทธ๋ฆฐ 2์ฐจ์ ์ฐ์ ๋: ๊ธฐ๋ณธย
์ด๋ฒ์๋ 3์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์ฐ์ ๋๋ก ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค. ์ด์ ์๋ ์ธ๊ธํ๋ฏ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋
hue
,
col
,
size
๋ฑ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ถ ์ง์ด ์ค ์ ์๋ ํ๋ผ๋ฏธํฐ๋ก ์๊ฐํํ๋ฉด ๋ฉ๋๋ค.
style: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
markers: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
size: ๋ง์ปค ํฌ๊ธฐ ์ง์
sizes: ๋ง์ปค ํฌ๊ธฐ์ ๋ฒ์ ์ง์
legend='full': ๋ชจ๋ ๋ฐ์ดํฐํฌ์ธํธ ๋ณด์ด๊ฒ ํ๊ธฐ
hue_norm: ์์ ๋ฒ์ ์ง์
python
sns
.
relplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
hue
=
'island'
,
size
=
'island'
,
col
=
'sex'
,
palette
=
[
'gray'
,
'steelblue'
,
'g'
]
,
sizes
=
(
75
,
200
)
,
alpha
=
.5
,
kind
=
'scatter'
,
data
=
df_penguins
)
Seaborn์ผ๋ก ๊ทธ๋ฆฐ 3์ฐจ์ ์ฐ์ ๋ย
3) ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋: jointplot()
๊ฒฐํฉ๋ถํฌ(joint distribution)์ ์ฃผ๋ณ๋ถํฌ(marginal distribution)๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด
jointplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
jointplot()
์ ์ถ ์์ค(axes-level) ํจ์์
๋๋ค.
python
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
data
=
df_penguins
)
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
hue
=
'species'
,
data
=
df_penguins
)
jointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋ย
jointplot()
ํจ์์
kind='kde'
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ ๊ฐ์ ๋ถํฌ๋ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ์์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
python
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'hist'
,
space
=
0
,
size
=
5
,
ratio
=
4
,
data
=
df_penguins
)
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'hex'
,
space
=
0
,
size
=
5
,
ratio
=
4
,
data
=
df_penguins
)
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'reg'
,
space
=
0
,
size
=
5
,
ratio
=
4
,
data
=
df_penguins
)
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
kind
=
'kde'
,
hue
=
'species'
,
space
=
0
,
size
=
5
,
ratio
=
4
,
data
=
df_penguins
)
jointplot() ํจ์์ kind ์ต์
์ ๋ํด ๊ทธ๋ฆฐ ๋ค์ํ ๊ทธ๋ํย
์ด๋ฐ์๋ ์๋ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ ์ด๋ค ๊ทธ๋ํ๊ฐ ๋์ค๋์ง ํ์ธํด ๋ณด์ธ์.
python
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
marker
=
'+'
,
s
=
100
,
marginal_kws
=
dict
(
bins
=
25
,
fill
=
False
)
,
height
=
5
,
ratio
=
2
,
marginal_ticks
=
True
,
data
=
df_penguins
)
g
=
sns
.
jointplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
)
g
.
plot_joint
(
sns
.
kdeplot
,
color
=
'r'
,
zorder
=
0
,
levels
=
6
)
g
.
plot_marginals
(
sns
.
rugplot
,
color
=
'r'
,
height
=
-
.15
,
clip_on
=
False
,
data
=
df_penguins
)
jointplot() ํจ์์ ์ฌ๋ฌ ๊ทธ๋ํ ๊ฒน์ณ ๊ทธ๋ฆฌ๊ธฐย
๋ ๋ค์ํ ์ข
๋ฅ์ ๊ฒฐํฉ๋ถํฌ ๋ฐ ์ฃผ๋ณ๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ๊ทธ๋ํ ์์ค(figure-level) ์ธํฐํ์ด์ค์ธ
JointGrid
๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋ค์์
JointGrid
๋ฅผ ์ด์ฉํด ํ์คํ ๊ทธ๋จ๊ณผ ๋ฐ์ค๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์ฝ๋์
๋๋ค.
python
g
=
sns
.
JointGrid
(
data
=
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
)
g
.
plot_joint
(
sns
.
scatterplot
,
s
=
100
,
alpha
=
.5
,
edgecolor
=
'.2'
,
linewidth
=
.5
)
g
.
plot_marginals
(
sns
.
histplot
,
kde
=
True
)
g
=
sns
.
JointGrid
(
data
=
df_penguins
,
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
)
g
.
plot
(
sns
.
regplot
,
sns
.
boxplot
)
g
.
refline
(
x
=
45
,
y
=
16
)
JointGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํย
4) ์ฐ์ ๋ ํ๋ ฌ: pairplot()
์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix)์ ์ฌ๋ฌ ๋ณ์๋ค์ ๋ชจ๋ ๊ฐ๋ฅํ ์ด์ ์กฐํฉ์ ํ๋ ฌ ํํ๋ก ํํํ ๊ทธ๋ํ์
๋๋ค. ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
pairplot()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ํจ์๋ ๋ฐ์ดํฐ์
์ ๋ชจ๋ ์ซ์ํ ๋ณ์ ์์ ๋ํด ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ๋๊ฐ์ ์๋ ๊ฐ ๋ณ์์ ๋ถํฌ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํ์คํ ๊ทธ๋จ์ด๋ KDE ํ๋กฏ์ ๊ทธ๋ฆฝ๋๋ค.
python
sns
.
pairplot
(
df_penguins
)
pairplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌย
corner=True
์ต์
์ ์ถ๊ฐํ๋ฉด ์ฐ์ ๋ ํ๋ ฌ์ ์ ๋ฐ๋ง ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
python
sns
.
pairplot
(
df_penguins
,
corner
=
True
)
์ ๋ฐ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌย
์ํ๋ ํน์ ๋ณ์๋ฅผ ์ง์ ํด์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
python
sns
.
pairplot
(
df_penguins
,
x_vars
=
[
'bill_length_mm'
,
'bill_depth_mm'
,
'flipper_length_mm'
]
,
y_vars
=
[
'bill_length_mm'
,
'bill_depth_mm'
]
)
ํน์ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌย
python
sns
.
pairplot
(
df_penguins
,
kind
=
'hist'
,
height
=
2
)
2์ฐจ์ ํ์คํ ๊ทธ๋จ ์ฐ์ ๋ ํ๋ ฌย
python
sns
.
pairplot
(
df_penguins
,
kind
=
'kde'
)
2์ฐจ์ kde ์ฐ์ ๋ ํ๋ ฌย
python
sns
.
pairplot
(
df_penguins
,
plot_kws
=
dict
(
marker
=
'+'
,
linewidth
=
1
)
,
diag_kws
=
dict
(
fill
=
False
)
)
์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1ย
python
g
=
sns
.
pairplot
(
df_penguins
,
diag_kind
=
'kde'
)
g
.
map_lower
(
sns
.
kdeplot
,
levels
=
4
,
color
=
'.2'
)
์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2ย
3์ฐจ์ ์ด์์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๋ ค๋ฉด
hue
์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
python
sns
.
pairplot
(
df_penguins
,
hue
=
'species'
,
markers
=
[
'o'
,
's'
,
'D'
]
,
diag_kind
=
'hist'
)
3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1ย
python
sns
.
pairplot
(
df_penguins
,
hue
=
'species'
,
size
=
2
,
aspect
=
1.8
,
plot_kws
=
dict
(
linewidth
=
0.5
,
alpha
=
0.3
)
,
diag_kind
=
'kde'
,
diag_kws
=
dict
(
shade
=
True
)
)
3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2ย
๋ ์ธ๋ฐํ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ๊ทธ๋ํ ์์ค ์ธํฐํ์ด์ค์ธ
PairGrid
ํด๋์ค๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
PairGrid
ํด๋์ค๋ก๋ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ทธ๋ํ๋ฅผ ์ง์ ์ง์ ํ ์ ์์ต๋๋ค. ๋ค์์
kdeplot()
๊ณผ
histplot()
ํจ์๋ฅผ ์ด์ฉํด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ๊ณผ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์
๋๋ค.
python
g
=
sns
.
PairGrid
(
df_penguins
)
g
.
map_upper
(
sns
.
histplot
)
g
.
map_lower
(
sns
.
kdeplot
,
fill
=
True
)
g
.
map_diag
(
sns
.
histplot
,
kde
=
True
)
PairGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ์ฐ์ ๋ ํ๋ ฌย
5) ์๊ดํ๋ ฌ: heatmap(), clustermap()
heatmap
ํํธ๋งต(heatmap)์ ๋ฐ์ดํฐ๋ฅผ ์์์ ๊ฐ๋๋ก ํํํ๋ 2์ฐจ์ ๊ทธ๋ํฝ ํํ ๋ฐฉ์์
๋๋ค. ํํธ๋งต์ ๋ณ๋ ๊ฐ ๊ด๊ณ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ด ์ข์ต๋๋ค. ํํธ๋งต์ผ๋ก๋ ๋ค์ํ ๊ด๊ณ๋ฅผ ํํํ ์ ์๋๋ฐ ์ฌ๊ธฐ์๋ ์๊ดํ๋ ฌ์ ํํํด๋ณด๊ฒ ์ต๋๋ค.
python
df_wines
=
df_wines
.
sample
(
frac
=
1
,
random_state
=
7
)
.
reset_index
(
drop
=
True
)
corr
=
df_wines
.
corr
(
)
sns
.
heatmap
(
round
(
corr
,
1
)
,
annot
=
True
,
fmt
=
'.1f'
,
cmap
=
'coolwarm'
,
vmax
=
1.0
,
vmin
=
-
1.0
,
linecolor
=
'white'
,
linewidths
=
.05
)
sns
.
set
(
rc
=
{
'figure.figsize'
:
(
10
,
7
)
}
)
heatmap() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ์๊ดํ๋ ฌ ํํธ๋งตย
clustermap
ํด๋ฌ์คํฐ๋งต(clustermap)์ ๋ฐ์ดํฐ ์๊ฐํ ๊ธฐ๋ฒ ์ค ํ๋๋ก, ํํธ๋งต๊ณผ ๊ณ์ธต์ ํด๋ฌ์คํฐ๋ง์ ๊ฒฐํฉํ ํํ์
๋๋ค. Seaborn์ผ๋ก ํด๋ฌ์คํฐ๋งต์ ๊ทธ๋ฆฌ๋ ค๋ฉด
clustermap()
ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
clustermap()
ํจ์์๋
heatmap()
ํจ์์ ๋ฌ๋ฆฌ
standard_sacle
ํ๋ผ๋ฏธํฐ๊ฐ ์์ด ํด๋ฌ์คํฐ๋งต์ ๋ฒ์๋ฅผ 0~1๋ก ์ ๊ทํํ ์ ์์ต๋๋ค.
python
corr
=
df_wines
.
corr
(
)
sns
.
clustermap
(
corr
,
cmap
=
'coolwarm'
,
standard_scale
=
1
)
clustermap() ํจ์๋ก ๊ทธ๋ฆฐ ์๊ดํ๋ ฌ ํด๋ฌ์คํฐ๋งตย
6) ํ๊ท ๊ทธ๋ํ
Seaborn์ผ๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด
regplot()
๋๋
lmplot()
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋จผ์
regplot()
์ฌ์ฉ๋ฒ๋ถํฐ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
regplot
regplot()
ํจ์๋ ์ฐ์ ๋์ ์ ํ ํ๊ท์ (linear regression line)์ ํจ๊ป ๊ทธ๋ ค์ฃผ๋ ํจ์์
๋๋ค. ์ ํ ํ๊ท์ ์ฃผ๋ณ ์์์ ์ ๋ขฐ๊ตฌ๊ฐ(95%)์ ๋ํ๋
๋๋ค.
python
sns
.
regplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
data
=
df_penguins
)
regplot()์ผ๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํ๊ท ๊ทธ๋ํย
์ฌ๊ธฐ์
lowess=True
์ต์
์ ์ถ๊ฐํ๋ฉด ํ๊ท์ ์ ์ ํ์ด ์๋๋ผ ์ค์ํ ๋ฐ์ดํฐ์ ๊ฐ์ค์น๋ฅผ ๋์ด๋ ๊ตญ์ ํ๊ท(local regression) ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฝ๋๋ค.
lowess
๋
locally weighted robust scatterplot smoothing
์ ์ฝ์์
๋๋ค.
python
sns
.
regplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
lowess
=
True
,
data
=
df_penguins
)
๊ตญ์ ํ๊ท ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํย
scatter_kws: ์ ์์(facecolor, fc), ์ ํ
๋๋ฆฌ ์์(edgecolor, ec), ํฌ๊ธฐ(size, s), ํฌ๋ช
๋ ์ง์
color: ์ ์์ ์ง์
line_kws: ์ ๊ตต๊ธฐ(linewidth, lw), ์ ์คํ์ผ(line style, ls), ํฌ๋ช
๋ ์ง์
ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95)
python
sns
.
regplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
scatter_kws
=
{
'fc'
:
'gray'
,
'ec'
:
'gray'
,
's'
:
50
,
'alpha'
:
0.3
}
,
color
=
'r'
,
line_kws
=
{
'lw'
:
1.5
,
'ls'
:
'--'
,
'alpha'
:
0.5
}
,
ci
=
90
,
data
=
df_penguins
)
๋ค์ํ ์ต์
์ ์ ์ฉํ ํ๊ท ๊ทธ๋ํย
lmplot
lmplot()
์ญ์
regplot()
๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ๋จ,
lmplot()
์ ๊ทธ๋ํ ์์ค(figure-level) ํจ์๋ก
FacetGrid
๋ฅผ ๋ง๋ญ๋๋ค.
lmplot()
์ ๊ทธ๋ํ ์์ค ํจ์์ด๊ธฐ ๋๋ฌธ์
regplot()
์์์ ๋ฌ๋ฆฌ
hue
๋๋
col
์ต์
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
python
sns
.
lmplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
hue
=
'species'
,
data
=
df_penguins
)
sns
.
lmplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
col
=
'species'
,
data
=
df_penguins
)
lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ1ย
์ ์ฒด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ง๋ค๊ณ ์ถ๋ค๋ฉด ๋ค์ ์ฝ๋๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
truncate=False: ํ๊ท์ x์ถ ๋๊น์ง ํํํ์ง ์๊ธฐ
facet_kws=dict(sharex=False, sharey=False): x์ถ, y์ถ ๊ณต์ ํ์ง ์๊ธฐ
line_kws: ํ๊ท์ ์คํ์ผ ์ง์ ํ๊ธฐ
scatter_kws: ์ฐ์ ๋ ์ ์คํ์ผ ์ง์ ํ๊ธฐ
python
g
=
sns
.
lmplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
col
=
'species'
,
row
=
'sex'
,
height
=
4
,
truncate
=
False
,
line_kws
=
{
'color'
:
'steelblue'
,
'linestyle'
:
'--'
}
,
data
=
df_penguins
)
axes
=
g
.
axes
for
ax
in
axes
.
ravel
(
)
:
sns
.
regplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
fit_reg
=
False
,
scatter_kws
=
{
'fc'
:
'gray'
,
'ec'
:
'none'
,
's'
:
30
,
'alpha'
:
0.3
}
,
ax
=
ax
,
data
=
df_penguins
)
lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ2ย
residplot
resideplot()
์ ์ค์ ๋ฐ์ดํฐํฌ์ธํธ์ ํ๊ท์ ๊ณผ์ ์์ฐจ(residuals)๋ฅผ ํํํ๋ ํจ์์
๋๋ค.
python
sns
.
residplot
(
x
=
'bill_length_mm'
,
y
=
'bill_depth_mm'
,
lowess
=
True
,
data
=
df_penguins
)
resideplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ฐจ ๊ทธ๋ํย
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ๋ชจ๋ ์๊ณ ๋ง์ผ์
จ์ต๋๋ค.
์ฐธ๊ณ ๋ฌธํ
[1] ๋คํฌํ๋ก๊ทธ๋๋จธ, ๏ฝขKernel Density Estimation(์ปค๋๋ฐ๋์ถ์ )์ ๋ํ ์ดํด๏ฝฃ, ๋คํฌํ๋ก๊ทธ๋๋จธ, "
https://darkpgmr.tistory.com/147
"
[2] ์ด์ ํ, ๏ฝขseaborn regplot vs lmplot๏ฝฃ, Pega Devlog, "
https://jehyunlee.github.io/2022/06/06/Python-DS-103-snsreglmplot/
"
[3] Dipanjan (DJ) Sarkar, ๏ฝขThe Art of Effective Visualization of Multi-dimensional Data๏ฝฃ, Towards Data Science, "
https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57
"
[4] Rfriend, ๏ฝข[Python] ๋ชจ์์ดํฌ ๊ทธ๋ํ (Mosaic Chart)๏ฝฃ, Rfriend, "
https://rfriend.tistory.com/418
"
[5] Seaborn, ๏ฝขseaborn.histplot๏ฝฃ, Seaborn, "
https://seaborn.pydata.org/generated/seaborn.histplot.html
"
[6] Seaborn, ๏ฝขseaborn.jointplot๏ฝฃ, Seaborn, "
https://seaborn.pydata.org/generated/seaborn.jointplot.html
"
[7] Seaborn, ๏ฝขseaborn.pairplot๏ฝฃ, Seaborn, "
https://seaborn.pydata.org/generated/seaborn.pairplot.html
"
[8] Statsmodels, ๏ฝขstatsmodels.graphics.mosaicplot.mosaic๏ฝฃ, Statsmodels, "
https://www.statsmodels.org/dev/generated/statsmodels.graphics.mosaicplot.mosaic.html
"
์ด์ ๊ธ
๋ค์ ๊ธ |
| Markdown | [](https://www.snugarchive.com/)
- [ํ](https://www.snugarchive.com/)
- [๊ธ](https://www.snugarchive.com/blog/posts/)
- [ํ๋ก์ ํธ](https://www.snugarchive.com/blog/projects/)
- [๋ฌธ์](https://www.snugarchive.com/contact/)
- [ํ๊ทธ](https://www.snugarchive.com/tags/)
- [ํ](https://www.snugarchive.com/)
- [๊ธ](https://www.snugarchive.com/blog/posts/)
- [์ปดํจํฐ ๊ณผํ](https://www.snugarchive.com/blog/category/computer-science/)
- [๋ฐ์ดํฐ ๊ณผํ](https://www.snugarchive.com/blog/category/data-science/)
- [ํ๊ฒฝ ์ค์ ](https://www.snugarchive.com/blog/category/environment-setup/)
- [์ํ](https://www.snugarchive.com/blog/category/mathematics/)
- [์์ฐ์ด](https://www.snugarchive.com/blog/category/natural-language/)
- [ํ๋ก๊ทธ๋๋ฐ ์ธ์ด](https://www.snugarchive.com/blog/category/programming-language/)
- [์น ๊ฐ๋ฐ](https://www.snugarchive.com/blog/category/web-development/)
- [ํ๋ก์ ํธ](https://www.snugarchive.com/blog/projects/)
- [๋ฌธ์](https://www.snugarchive.com/contact/)
- [ํ๊ทธ](https://www.snugarchive.com/tags/)
[๋ฐ์ดํฐ ๊ณผํ](https://www.snugarchive.com/blog/category/data-science/)[๋ฐ์ดํฐ ์๊ฐํ](https://www.snugarchive.com/blog/category/data-science/visualization/)
# ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ์ฌํํธ
## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ
Last Updated
2024-09-10
Published
2023-01-12
- [Python Seaborn](https://www.snugarchive.com/tag/python-seaborn/)
11๋ถ
#### ๋ชฉ์ฐจ
1. [์ค๋น](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EC%A4%80%EB%B9%84)
- [๊ธฐ๋ณธ ํ๊ฒฝ ์ค์ ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EA%B8%B0%EB%B3%B8-%ED%99%98%EA%B2%BD-%EC%84%A4%EC%A0%95)
- [๋ฐ์ดํฐ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8D%B0%EC%9D%B4%ED%84%B0)
2. [๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ๋ฒ์ฃผํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%8B%9C%EA%B0%81%ED%99%94-%EB%B2%94%EC%A3%BC%ED%98%95)
- [1\) ๋น๋ ๋ง๋๊ทธ๋ํ: countplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EB%B9%88%EB%8F%84-%EB%A7%89%EB%8C%80%EA%B7%B8%EB%9E%98%ED%94%84-countplot)
- [2\) ์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ: barplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%9A%94%EC%95%BD-%ED%86%B5%EA%B3%84%EB%9F%89-%EB%A7%89%EB%8C%80%EA%B7%B8%EB%9E%98%ED%94%84-barplot)
- [3\) ํฌ์ธํธ ํ๋กฏ: pointplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%ED%8F%AC%EC%9D%B8%ED%8A%B8-%ED%94%8C%EB%A1%AF-pointplot)
- [4\) ์์๊ทธ๋ฆผ: boxplot(), boxenplot(), violinplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%83%81%EC%9E%90%EA%B7%B8%EB%A6%BC-boxplot-boxenplot-violinplot)
- [5\) ๋ชจ์์ดํฌ ๊ทธ๋ํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EB%AA%A8%EC%9E%90%EC%9D%B4%ED%81%AC-%EA%B7%B8%EB%9E%98%ED%94%84)
3. [๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ์์นํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%8B%9C%EA%B0%81%ED%99%94-%EC%88%98%EC%B9%98%ED%98%95)
- [1\) ์ ๊ทธ๋ํ: stripplot(), swarmplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EC%A0%90%EA%B7%B8%EB%9E%98%ED%94%84-stripplot-swarmplot)
- [2\) ์ ๋ถ๊ทธ๋ํ: rugplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%84%A0%EB%B6%84%EA%B7%B8%EB%9E%98%ED%94%84-rugplot)
- [3\) ํ์คํ ๊ทธ๋จ: histplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%ED%9E%88%EC%8A%A4%ED%86%A0%EA%B7%B8%EB%9E%A8-histplot)
- [4\) ์ปค๋๋ฐ๋ํจ์ ๊ทธ๋ํ: kdeplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%BB%A4%EB%84%90%EB%B0%80%EB%8F%84%ED%95%A8%EC%88%98-%EA%B7%B8%EB%9E%98%ED%94%84-kdeplot)
- [5\) ๊ฒฝํ์ ๋์ ๋ถํฌํจ์: ecdfplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EA%B2%BD%ED%97%98%EC%A0%81-%EB%88%84%EC%A0%81%EB%B6%84%ED%8F%AC%ED%95%A8%EC%88%98-ecdfplot)
4. [๋ค์ฐจ์ ๋ฐ์ดํฐ: ๊ด๊ณ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EA%B4%80%EA%B3%84)
- [1\) ์ ๊ทธ๋ํ: lineplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EC%84%A0%EA%B7%B8%EB%9E%98%ED%94%84-lineplot)
- [2\) ์ฐ์ ๋: scatterplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%82%B0%EC%A0%90%EB%8F%84-scatterplot)
- [3\) ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋: jointplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%EA%B2%B0%ED%95%A9%EC%A3%BC%EB%B3%80%EB%B6%84%ED%8F%AC%EB%8F%84-jointplot)
- [4\) ์ฐ์ ๋ ํ๋ ฌ: pairplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%82%B0%EC%A0%90%EB%8F%84-%ED%96%89%EB%A0%AC-pairplot)
- [5\) ์๊ดํ๋ ฌ: heatmap(), clustermap()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EC%83%81%EA%B4%80%ED%96%89%EB%A0%AC-heatmap-clustermap)
- [6\) ํ๊ท ๊ทธ๋ํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#6-%ED%9A%8C%EA%B7%80-%EA%B7%B8%EB%9E%98%ED%94%84)
5. [์ฐธ๊ณ ๋ฌธํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EC%B0%B8%EA%B3%A0-%EB%AC%B8%ED%97%8C)




Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด๋ณด์
[Snug Archive](https://www.snugarchive.com/)
์ง๋ ์๊ฐ์๋ ํ์ด์ฌ์ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ๋ณ์๊ฐ 1๊ฐ์ธ ๋จ๋ณ๋ ๋ฐ์ดํฐ(univariate data)๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ ์๊ฐ์๋ ๋ณ์๊ฐ 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ(bivariate data)์ 3๊ฐ ์ด์์ธ ๋ค๋ณ๋ ๋ฐ์ดํฐ(multivariate data)๋ฅผ ์๊ฐํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค. Seaborn ์ฌ์ฉ์ ์ํ ๊ธฐ๋ณธ ํ๊ฒฝ ์ค์ ๋ฐฉ๋ฒ๊ณผ ๊ทธ๋ํ ์คํ์ผ๋ง, 1์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์ถ์ ๋ถ๋ค์ [ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)์ ๋จผ์ ์ฝ์ผ์๊ธฐ๋ฅผ ์ถ์ฒ๋๋ฆฝ๋๋ค.
๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๊ทธ๋ํ์ ์ข
๋ฅ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
1. ๋ค์ฐจ์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ ์๊ฐํ
> - ๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ): catplot(kind='count')
> - ๋น๋ ๋ง๋๊ทธ๋ํ(๋ค์ค, ๋์ ): countplot
> - ์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ: barplot
> - ์์ฝ ํต๊ณ๊ฐ ํฌ์ธํธ๊ทธ๋ํ: pointplot
> - ์์๊ทธ๋ฆผ: boxplot, boxenplot, violinplot
1. ๋ค์ฐจ์ ์์นํ ๋ฐ์ดํฐ ์๊ฐํ
> - ์ ๊ทธ๋ํ(dot plot): stripplot, swarmplot
> - ์ ๋ถ๊ทธ๋ํ(rug plot): rugplot
> - ํ์คํ ๊ทธ๋จ(histogram): histplot
> - ๋ฐ๋๊ทธ๋ฆผ(density plot): kdeplot
> - ๊ฒฝํ์ ๋์ ๋ถํฌํจ์(empirical cumulative distribution function): ecdfplot
1. ๋ค์ฐจ์ ๋ฐ์ดํฐ ๊ด๊ณ ์๊ฐํ
> - ์ ๊ทธ๋ํ(line plot): lineplot
> - ์ฐ์ ๋(scatter plot): scatterplot
> - ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋(joint/marginal distribution plot): jointplot
> - ์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix): pairplot
> - ์๊ด ํ๋ ฌ(correlation matrix): heatmap, clustermap
> - ํ๊ท ๊ทธ๋ํ(regression plot): regplot, lmplot, residplot




Seaborn ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ ๋ก๋๋งต
## ์ค๋น
์ค์ต์ ์ํด์๋ ๊ฐ๋ฐ ํ๊ฒฝ(development environments)๊ณผ ๋ฐ์ดํฐ๊ฐ ํ์ํฉ๋๋ค. ๋จผ์ ๊ฐ๋ฐ ํ๊ฒฝ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
### ๊ธฐ๋ณธ ํ๊ฒฝ ์ค์
๊ธ์์๋ ๊ฐ๋ฐ ํ๊ฒฝ์ผ๋ก ์ฃผํผํฐ ๋
ธํธ๋ถ(Jupyter notebook)์ ์ฌ์ฉํ์ต๋๋ค. ์ฌ๊ธฐ์๋ ์๊ฐํ ์ค์ต์ ํ๋๋ฐ ํ์ํ ์ต์ํ์ ์ค์ ๋ง ์ ์ฉํ๊ฒ ์ต๋๋ค. ์ฝ๋๋ณ ์์ธํ ์ค๋ช
์ Matplotlib ์ฌ์ฉ๋ฒ(์์ )์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฃผํผํฐ ๋
ธํธ๋ถ์ ์์ธํ ํ๊ฒฝ์ค์ ๋ฐฉ๋ฒ์ [์ฃผํผํฐ ๋
ธํธ๋ถ ํ๊ฒฝ ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/jupyter-notebook-setup/)๋ฅผ ์ฐธ์กฐํ์๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
python# ํจํค์ง ์ํฌํธimport numpy as np # Numpy(๋ํ์ด) ํจํค์ง ์ํฌํธimport pandas as pd # pandas(ํ๋ค์ค) ํจํค์ง ์ํฌํธimport matplotlib.pyplot as plt # Matplotlib(๋งทํ๋กฏ๋ฆฝ) ํจํค์ง์ pyplot ๋ชจ๋์ plt๋ก ์ํฌํธfrom matplotlib import rcParams # ํ๊ธ ํ๊ฒฝ ์ค์ ์ ์ํ rcParams ์ํฌํธimport seaborn as sns # Seaborn(์จ๋ณธ) ํจํค์ง ์ํฌํธimport warnings# ํ๊ธ ํ๊ฒฝ ์ค์ def setting_styles_basic():rcParams['font.family'] = 'Malgun Gothic' # Windows# rcParams['font.family'] = 'AppleGothic' # MacrcParams['axes.unicode_minus'] = False # ํ๊ธ ํฐํธ ์ฌ์ฉ ์, ๋ง์ด๋์ค ๊ธฐํธ๊ฐ ๊นจ์ง๋ ํ์ ๋ฐฉ์งsetting_styles_basic()# ๊ฒฝ๊ณ ์ฐฝ ๋ฌด์warnings.filterwarnings('ignore')
```
๋ค์์ผ๋ก๋ ๊ทธ๋ํ์ ์ค์ผ์ผ(scale)์ ์กฐ์ ํ๊ฒ ์ต๋๋ค. ์ค์ผ์ผ ์กฐ์ ์ `sns.set_context` ํจ์๋ฅผ ์ด์ฉํด ์ค์ ํ ์ ์์ต๋๋ค. Seaborn์ ๋ค์ํ ์คํ์ผ๋ง ๋ฐฉ๋ฒ์ [ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)์ ์คํ์ผ๋ง ๋ถ๋ถ์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฝ๋ ์คํ ๊ฒฐ๊ณผ๋ ๊ทธ๋ํ ์ ์ญ์ ์ ์ฉ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.set_context('paper', # notebook, talk, posterrc={'font.size':15,'xtick.labelsize':15,'ytick.labelsize':15,'axes.labelsize':15})
```
์ค์ต์ ์ํ ๊ธฐ๋ณธ์ ์ธ ํ๊ฒฝ ์ค์ ์ ๋ง์ณค๋ค๋ฉด ๋ค์์ ๋ฐ์ดํฐ๋ฅผ ์ค๋นํ ์ฐจ๋ก์
๋๋ค.
### ๋ฐ์ดํฐ
์ค์ต์ ์ํด์ Seaborn์ ๋ด์ฅ ๋ฐ์ดํฐ๋ฅผ `load_dataset()` ํจ์๋ฅผ ์ด์ฉํด ๋ก๋ฉํด ์ค๊ฒ ์ต๋๋ค. ํน์ ๋ฐ์ดํฐ์
์ Sklearn(์ฌ์ดํท๋ฐ)์์ ๋ถ๋ฌ์ pandas์ DataFrame์ผ๋ก ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค. ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythondf_titanic = sns.load_dataset('titanic') # ํ์ดํ๋ํธ ๋ฐ์ดํฐdf_iris = sns.load_dataset('iris') # ๋ถ๊ฝ ๋ฐ์ดํฐdf_penguins = sns.load_dataset('penguins') # ํญ๊ท ๋ฐ์ดํฐdf_tips = sns.load_dataset('tips') # ํ ๋ฐ์ดํฐdf_diamonds = sns.load_dataset('diamonds') # ๋ค์ด์๋ชฌ๋ ๋ฐ์ดํฐdf_planets = sns.load_dataset('planets') # ํ์ฑ ๋ฐ์ดํฐdf_flights = sns.load_dataset('flights') # ๋นํ ๋ฐ์ดํฐfrom sklearn.datasets import load_winewine_data = load_wine()df_wines = pd.DataFrame(data=wine_data.data, # ์์ธ ๋ฐ์ดํฐcolumns=wine_data.feature_names)
```
๊ทธ๋ผ ์ง๊ธ๋ถํฐ ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ ๋ณ๋์ด 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ์ ๋ณ๋์ด 3๊ฐ ์ด์์ธ ๋ฐ์ดํฐ๋ฅผ ํฌํจํฉ๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋ํ๋ก ํํํ ๋๋ ์์์ผ๋ก ๊ตฌ๋ถํ๋ `hue`, ์บ๋ฒ์ค๋ก ๊ตฌ๋ถํ๋ `col`, ์ ํฌ๊ธฐ๋ก ๊ตฌ๋ถํ๋ `size` ๋ฑ์ ํ๋ผ๋ฏธํฐ๋ฅผ ์ด์ฉํด ์๊ฐํ ์ฐจ์์ ๋ํ๋๊ฐ ์ ์์ต๋๋ค. ๋จผ์ ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค.
## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ๋ฒ์ฃผํ
๋ค๋ณ๋ ๋ฒ์ฃผํ ์๋ฃ๋ฅผ ์๊ฐํํ๋ Seaborn์ ๊ทธ๋ํ๋ ๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ, ๋ค์ค, ๋์ )๊ฐ ์์ต๋๋ค.
### 1\) ๋น๋ ๋ง๋๊ทธ๋ํ: countplot()
๋น๋ ๋ง๋๊ทธ๋ํ(์นด์ดํธํ๋กฏ)์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ์ ๊ฐ์๋ฅผ ํํํฉ๋๋ค.
#### ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ
๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ ๋ ๋ณ๋์ ๋ํ ๋น๋ ๋ง๋๊ทธ๋ํ 2๊ฐ๋ฅผ ๊ฐ๊ฐ์ ์บ๋ฒ์ค(canvas)์ ๋ณ๋ ฌ๋ก ๋์ดํ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `catplot()` ํจ์์ `kind='count'` ์ `col` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. `countplot()` ํจ์๋ก๋ ๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
```
pythonsns.catplot(x='class',col='who', # ์บ๋ฒ์ค ๋ถ๋ฆฌํ๊ธฐkind='count', # ๋น๋ ๋ง๋๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐdata=df_titanic)
```




countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ
#### ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ `countplot()` ๋๋ `catplot()`์ `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `hue` ์ต์
์ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํ๋ ํ๋ผ๋ฏธํฐ์
๋๋ค. ๋จผ์ ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ถํฐ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
##### ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
`countplot()` ํจ์ ๋๋ `caplot()` ํจ์๋ก ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด ํด๋น ํจ์์ `x` ํ๋ผ๋ฏธํฐ์ ๊ฐ๋ก์ถ ๋ฒ์ฃผ๋ก ์ฌ์ฉํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๊ณ , `hue` ํ๋ผ๋ฏธํฐ์ ๋ค๋ฅธ ์์์ผ๋ก ๊ตฌ๋ถํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.countplot(x='class', hue='who', data=df_titanic) # ์ฝ๋1# ๋๋# ์ฝ๋2sns.catplot(x='class', hue='who', kind='count',palette='pastel', # ์์ ํ๋ ํธ ์ง์ : {'man': 'b', 'woman': 'g', 'child': 'r'}edgecolor='.6', # ๋ง๋ ํ
๋๋ฆฌ ์์ ํฌ๋ช
๋ ์ง์ data=df_titanic)
```




countplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ
`histplot()` ํจ์์ `multiple='dodge'` ์ต์
์ ์ฃผ์ด๋ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `histplot()` ํจ์๋ ์์นํ ์๋ฃ๋ฅผ ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ง๋ค ๋ ์ฌ์ฉํ๋ ํจ์์ด์ง๋ง, ํ์คํ ๊ทธ๋จ์ ๋ง๋ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ์ฃผ๊ณ x์ถ ๋๊ธ์ ์์ ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ผ๋ฐ ๋ง๋๊ทธ๋ํ์ฒ๋ผ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonax = sns.histplot(x='sex', hue='survived',multiple='dodge', # ๋ค์ค ๋ง๋๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐshrink=.8, # ๋ง๋ ์ฌ์ด ๊ฐ๊ฒฉ ์กฐ์ data=df_titanic)ax.tick_params(bottom=False) # x์ถ ๋๊ธ ์จ๊ธฐ๊ธฐ
```




histplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ
์ด๋ฒ์๋ ์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
##### ์ํ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ๋ ์ฌ์ฉํ ํจ์์ `x` ํ๋ผ๋ฏธํฐ ๋์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.countplot(y='class', hue='who', data=df_titanic) # ์ฝ๋1# ๋๋sns.catplot(y='class', hue='who', kind='count',palette='pastel', edgecolor='.6',data=df_titanic) # ์ฝ๋2
```




countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ฐ๋ก ๊ทธ๋ฃนํ ๋ง๋๊ทธ๋ํ
#### ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
Seaborn์ผ๋ก ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๋ง๋ค๋ ค๋ฉด `histplot()` ํจ์์ `multiple='stack'` ์ต์
์ ์ฃผ๋ฉด ๋ฉ๋๋ค.
##### ์์ง ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
```
pythonax = sns.histplot(x='sex', hue='survived',multiple='stack', # ๋์ ๋ง๋๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐshrink=.8, # ๋ง๋ ์ฌ์ด ๊ฐ๊ฒฉ ์กฐ์ data=df_titanic)ax.tick_params(bottom=False) # x์ถ ๋๊ธ ์ ๋ณด์ด๊ฒ ํ๊ธฐ
```




histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์์ง ๋์ ๋ง๋๊ทธ๋ํ
##### ์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `x` ํ๋ผ๋ฏธํฐ ๋์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonax = sns.histplot(y='sex', hue='survived',multiple='stack', # ๋์ ๋ง๋๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐshrink=.8, # ๋ง๋ ์ฌ์ด ๊ฐ๊ฒฉ ์กฐ์ palette='pastel', # ์์ ํ๋ ํธ ์ง์ data=df_titanic);ax.tick_params(left=False) # y์ถ ๋๊ธ ์ ๋ณด์ด๊ฒ ํ๊ธฐ
```




histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์ํ ๋์ ๋ง๋๊ทธ๋ํ
### 2\) ์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ: barplot()
์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ๋ ๋ฒ์ฃผํ ์๋ฃ์ ๋ํ ์์นํ ๋ฐ์ดํฐ๋ฅผ ๋ถํธ์คํธ๋ฉ ์ํ๋ง(์๋ณธ ๋ฐ์ดํฐ์ ๋์ผํ ํฌ๊ธฐ์ ์ํ์ ์ฌ๋ฌ ๋ฒ ๋ณต์ ์ถ์ถ)ํ์ฌ ์ป์ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ ๊ทธ ํ๊ท ์ ์ ๋ขฐ๊ตฌ๊ฐ(confidence interval)์ ๋ํ๋ธ ๋ง๋๊ทธ๋ํ์
๋๋ค. ์ ๋ขฐ๊ตฌ๊ฐ์ ๋ง๋ ์ ๊ฒ์ ์ ์ค์ฐจ ๋ง๋(error bar)๋ก ํํ๋ฉ๋๋ค. ์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `barplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='bar'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก๋ ๋ณต์ ์ํ๋ง๋ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ 95% ์ ๋ขฐ๊ตฌ๊ฐ์ด ํํ๋์ง๋ง `estimator` ํ๋ผ๋ฏธํฐ์ `ci` ํ๋ผ๋ฏธํฐ๋ก ๊ฐ๊ฐ ์์ฝ ํต๊ณ๊ฐ๊ณผ ์ ๋ขฐ๊ตฌ๊ฐ์ ์ง์ ํ ์ ์์ต๋๋ค. ์ต์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
> - estimator: ์ค์๊ฐ `np.median`, ํฉ๊ณ `np.sum` ๋ฑ
> - ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95), `sd`๋ก ์ค์ ์ ํ์คํธ์ฐจ(standard deviation)๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ, `None`์ผ๋ก ์ค์ ์ ์ค์ฐจ ๋ง๋ ์ ๊ฑฐ
> - n\_boot: ๋ถํธ์คํธ๋ฉ ์ํ๋ง ํ์(๊ธฐ๋ณธ๊ฐ: 1000)
๋จผ์ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๋ฒ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
#### ๊ธฐ๋ณธ
##### ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ
์์ง ํ๊ท ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill', data=df_tips)# ๋๋sns.catplot(x='day', y='total_bill', kind='bar', data=df_tips)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ
##### ์ํ ์์ฝ ๋ง๋๊ทธ๋ํ
๋ง์ผ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `barplot()` ํจ์์ `orient='h'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.barplot(x='total_bill', y='day', orient='h', data=df_tips)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ง๋๊ทธ๋ํ
#### ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
`barplot()` ํจ์์ `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ๋ฉด ์์์ผ๋ก ๊ตฌ๋ถ๋๋ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
##### ์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
๋ค์์ ๋ณ๋์ด 3๊ฐ์ธ ๋ฐ์ดํฐ๋ฅผ ์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ก ํํํ๋ ์์ ์ฝ๋์
๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill',hue='smoker', data=df_tips)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํ
##### ์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ผ๋ฉด `orient=h` ํ๋ผ๋ฏธํฐ๊ฐ์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.barplot(x='total_bill', y='day',hue='smoker', orient='h', data=df_tips)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํ
#### ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `barplot()` ํจ์์ `dodge=False`์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. Seaborn์์ ๋์ ๋ง๋๊ทธ๋ํ๋ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋์ ์ต๋๊ฐ ์์ ๋ค๋ฅธ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋๋ฅผ ์์์ ๋ง๋๋ ๊ฒ์ด ์๋๋ผ ๊ทธ๋ํ ์์ฒด๋ฅผ ์๋ก ๊ฒน์ณ์ ๊ทธ๋ฆฐ ๊ฒ์
๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill',hue='smoker', dodge=False,data=df_tips)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ1
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋ `barplot()` ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํด์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythons1 = sns.barplot(x='species', y='sepal_length',color='coral', ci=None, data=df_iris)s2 = sns.barplot(x='species', y='petal_length',color='powderblue', ci=None, data=df_iris)
```




barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ2
์ ๊ทธ๋ํ์์ ๋ง๋์ y์ถ๊ฐ(์์น ๋ ๋ถ๋ถ)์ ๊ฐ๊ฐ `sepal_length`์ ํ๊ท ๊ณผ `petal_length`์ ํ๊ท ์ ๋ํ๋
๋๋ค.
### 3\) ํฌ์ธํธ ํ๋กฏ: pointplot()
ํฌ์ธํธํ๋กฏ์ ๋ง๋๊ทธ๋ํ์ ๋์ผํ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋์ ํ๊ท ๊ฐ์ ๋ง๋ ๋์ ์ (point)์ผ๋ก ํํํฉ๋๋ค. ํฌ์ธํธํ๋กฏ์ `pointplot()` ํจ์๋ฅผ ์ฌ์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ํฌ์ธํธํ๋กฏ์ ํ ํ๋ฉด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๋น๊ตํ ๋ ์ ์ฉํฉ๋๋ค.
```
pythonsns.pointplot(x='day', y='total_bill', data=df_tips)# ๋๋sns.catplot(x='day', y='total_bill', kind='point', data=df_tips)
```




pointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํฌ์ธํธ ํ๋กฏ
๋ง์ผ ์ ๋ขฐ๊ตฌ๊ฐ์ด ์๋๋ผ ํ์คํธ์ฐจ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด `ci='sd'`๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ ๊ณผ ํฌ์ธํธ๋ฅผ ๋ค๋ฅธ ๋ชจ์์ผ๋ก ํํํ ์๋ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.pointplot(x='class', y='survived', hue='sex',palette={'male': 'g', 'female': 'm'},markers=['^', 'o'], # ๋ง์ปค ์ง์ linestyles=['-', '--'], # ์ ์คํ์ผ ์ง์ data=df_titanic)
```




์ต์
์ ์ถ๊ฐํ ํฌ์ธํธ ํ๋กฏ
### 4\) ์์๊ทธ๋ฆผ: boxplot(), boxenplot(), violinplot()
์์๊ทธ๋ฆผ(๋ฐ์คํ๋กฏ)์ ๋ฐ์ดํฐ์ ๋ถ์๋ฅผ 5๊ฐ์ง ์์ฝ ์์น(five-number summary)๋ก ์ ๊ณตํ๋ ๋ํ์
๋๋ค.
> - ์ 3์ฌ๋ถ์์ (Q3): ์ ์ฒด ๋ฐ์ดํฐ ์ค ์์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
> - ์ 2์ฌ๋ถ์์ (Q2 ๋๋ ์ค์๊ฐ): ์ ์ฒด ๋ฐ์ดํฐ์ 50%์ ํด๋นํ๋ ๊ฐ(์ค์๊ฐ), ๋ฐ์ค ๋ด๋ถ์ ์ ์ผ๋ก ํ์
> - ์ 1์ฌ๋ถ์์ (Q1): ์ ์ฒด ๋ฐ์ดํฐ ์ค ํ์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์๋์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
> - ์ฌ๋ถ์ ๋ฒ์ (IQR): Q3 - Q1, ๋ฐ์ค์ ๋์ด๋ก ํํ
> - ์ต๋๊ฐ (Maximum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ํฐ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
> - ์ต์๊ฐ (Minimum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ์์ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์๋์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
> - ์ด์์น (Outliers): ์ผ๋ฐ์ ์ผ๋ก Q1 - 1.5IQR ๋ฏธ๋ง์ด๊ฑฐ๋ Q3 + 1.5IQR ์ด๊ณผ์ธ ๊ฐ๋ค์ ๊ฐ๋ณ ์ ์ผ๋ก ํ์
#### ๊ธฐ๋ณธ
Seaborn์์ ์์๊ทธ๋ฆผ์ ๋ง๋ค๋ ค๋ฉด `boxplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ 'kind='box'\` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.boxplot(data=df_iris)# ๋๋sns.catplot(data=df_iris, kind='box')
```




boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ง ์์๊ทธ๋ฆผ
๋ง์ผ ์์๊ทธ๋ฆผ์ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `orient='h'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.boxplot(data=df_iris, orient='h')
```




boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผ
3์ฐจ์ ๋ฐ์คํ๋กฏ์ `hue` ์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ๋ํ๋ฉด ๋น์ทํ ์์ฑ์ ๋ฐ์ดํฐ๋ผ๋ฆฌ ๋ถ๋ฅํ ์ ์์ต๋๋ค.
```
pythondf_tips['weekend'] = df_tips['day'].isin(['Sat', 'Sun'])sns.boxplot(x='total_bill', y='day', hue='weekend',orient='h',dodge=False,data=df_tips)
```




boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผ2
#### ๋ฐ์จ ํ๋กฏ
๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ฌ ๊ฐ์ ๋ถ์๋ก ๋๋ ๋ฐ์คํ๋กฏ์
๋๋ค. ๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ์
์ ๋ ๋ง์ ๋ถ์์(quantiles)๋ก ๋๋์ด ๊ธฐ์กด์ ์์๊ทธ๋ฆผ๋ณด๋ค ์ด์์น(outliers)์ ๋ํด ๋ ๋ง์ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ฐ๋ผ์, ๋ฐ์จ ํ๋กฏ์ ํฐ ๋ฐ์ดํฐ์
์ ์ฒ๋ฆฌํ๊ธฐ์ ์ ํฉํฉ๋๋ค.
๋ฐ์จ ํ๋กฏ์ ๋ง๋ค๋ ค๋ฉด `boxenplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='boxen'` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.boxenplot(x='color', y='price',data=df_diamonds.sort_values('color'))# ๋๋sns.catplot(x='color', y='price', kind='boxen',data=df_diamonds.sort_values('color'))
```




boxenplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์จ ํ๋กฏ
#### ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ
๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ์์๊ทธ๋ฆผ๊ณผ KDE ๋ฐฉ๋ฒ์ ์ด์ฉํด ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์(์ปค๋๋ฐ๋์ถ์ ํจ์)๋ฅผ ํฉ์น ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `violinplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='violin'` ์ต์
์ ์ถ๊ฐํด๋ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
```
pythonsns.violinplot(x='total_bill', y='day', data=df_tips)# ๋๋sns.catplot(x='total_bill', y='day', kind='violin', data=df_tips)
```




violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ
์ด์ง ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด `hue` ์ `split=True` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.




violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ2
### 5\) ๋ชจ์์ดํฌ ๊ทธ๋ํ
๋ง๋๊ทธ๋ํ ์ธ์๋ ๋ณ๋์ด ๋ชจ๋ ๋ฒ์ฃผํ์ธ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋ ๋ชจ์์ดํฌ ๊ทธ๋ํ(mosaic plot)๋ฅผ ์ฌ์ฉํ๊ธฐ๋ ํฉ๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๊ทธ๋ฃน ๋ด์ ๋ฐ์ดํฐ ๋ฐฑ๋ถ์จ์ ๋ณด์ฌ์ฃผ๋ ๋์ ๋ง๋๊ทธ๋ํ์
๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๋ณ์๊ฐ 3๊ฐ ์ด์์ผ ๋๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ชจ์์ดํฌ ๊ทธ๋ํ๋ `statmodels.graphics.mosaic` ํจํค์ง์ `mosaic()` ํจ์๋ฅผ ์ด์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonfrom statsmodels.graphics.mosaicplot import mosaicimport matplotlib.pyplot as pltprops = lambda key: {'color': 'teal' if '1' in key else 'lightgray'}labelizer = lambda k: {('female','1'): '์ฌ์ฑ\n(์์กด)', ('female','0'): '์ฌ์ฑ\n(์ฌ๋ง)',('male','1'): '๋จ์ฑ\n(์์กด)', ('male', '0'): '๋จ์ฑ\n(์ฌ๋ง)'}[k]mosaic(df_titanic.sort_values('sex'),['sex', 'survived'],properties=props, # ์์ ๋ณ๊ฒฝlabelizer=labelizer, # ๋ผ๋ฒจ ๋ณ๊ฒฝaxes_label=False) # ์ถ ๋ผ๋ฒจ ์จ๊ธฐ๊ธฐplt.title('ํ์ดํ๋ํธ ์ฑ๋ณ ์์กด์', fontsize=17) # ์ ๋ชฉ ๋ด์ฉ ๋ฐ ๊ธ์ ํฌ๊ธฐ ์ค์
```




mosaic ํจ์๋ก ๊ทธ๋ฆฐ ๋ชจ์์ดํฌ ํ๋กฏ
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ์๋ ๋ค๋ณ๋ ์์นํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ์์นํ
### 1\) ์ ๊ทธ๋ํ: stripplot(), swarmplot()
์ ๊ทธ๋ํ๋ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ผ๋ก ๋ํ๋ธ ๋ํ์
๋๋ค. ์ ๊ทธ๋ํ๋ฅผ ์ด์ฉํ๋ฉด ๋ฐ์ดํฐ์ ์ค์ ์์น์ ๋ถํฌ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ต๋๋ค. Seaborn์์ ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ํจ์๋ `stripplot()`์
๋๋ค.
#### stripplot
```
pythonsns.stripplot(data=df_tips)# ๋๋sns.catplot(kind='strip', data=df_tips)
```




stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ
`stripplot()` ํจ์์ `jitter` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ผ๋ ฌ๋ก ๊ทธ๋ฆด ์ ์์ต๋๋ค.
> - jitter: ์งํฐ(jitter)๋ ๋ฐ์ดํฐ ๊ฐ์ ์ฝ๊ฐ์ ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ, ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐ ๊ฐ์ด ์กฐ๊ธ์ฉ ์์ง์ฌ์ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ ๋ฐ์ดํฐ๊ฐ ๊ทธ๋ํ์ ์ฌ๋ฌ ๋ฒ ๊ฒน์ณ์ ํ์๋๋ ํ์์ ๋ง์์ค
```
pythonsns.stripplot(x='total_bill', y='smoker',jitter=False,data=df_tips)
```




stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ2
๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์๋ก ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์งํ๋ ค๋ฉด `dodge=True` ์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
> - dodge=True: hue๋ก ๊ตฌ๋ถ๋ ๊ทธ๋ฃน ์ฌ์ด ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ๋ฐ์ดํฐ๊ฐ ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์ง
```
pythonsns.stripplot(x='tip', y='day',palette='Spectral', # ์์ ํ๋ ํธ ์ง์ dodge=True,data=df_tips)
```




stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ3
`dodge=True` ์ต์
์ฒ๋ผ ์ ๊ทธ๋ํ์์ ๋ฐ์ดํฐ ํฌ์ธํธ๋ค์ด ์๋ก ๊ฒน์น์ง ์๊ณ ์์ ๋ฌด๋ฆฌ์ฒ๋ผ ๋ณด์ด๊ฒ ๊ทธ๋ํ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค. ์ด๋ ์ฌ์ฉํ๋ ํจ์๊ฐ `swarmplot()`์
๋๋ค.
#### swarmplot
`swarmplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ์ ๋ํ์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ผ(swarm)์ฒ๋ผ ๋ฌด๋ฆฌ๋ฅผ ๋ง๋ค์ด ๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์ค์ฒฉ๋๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค. ๋ผ ํ๋กฏ์ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.swarmplot(data=df_tips)# ๋๋sns.catplot(kind='swarm', data=df_tips)
```




swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ์ ์ฒด ๋ณ์
`x`์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ ๋ณ์์ ๋ํ ๋ผ ํ๋กฏ์ ๋ง๋ค ์ ์์ต๋๋ค.
```
pythonsns.swarmplot(x='day', y='total_bill', data=df_tips)# ๋๋sns.catplot(x='day', y='total_bill', kind='swarm', data=df_tips)
```




swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ํน์ ๋ณ์
์ค์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ด ์๋๋ผ ์ ๋ถ(rug)์ผ๋ก ํํํ ์๋ ์์ต๋๋ค.
### 2\) ์ ๋ถ๊ทธ๋ํ: rugplot()
์ค์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ์ ๋ถ์ผ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด `rugplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `rugplot()`์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๊ฐ ์ถ ์์ ๋ณด์ฌ์ค๋๋ค.
```
pythonsns.rugplot(x='total_bill', y='tips', data='df_tips')
```




rugplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ถ๊ทธ๋ํ
๋ณดํต ์ ๋ถ๊ทธ๋ํ๋ ๋ค๋ฅธ ๊ทธ๋ํ์ ํจ๊ป ๊ทธ๋ฆฝ๋๋ค. ๊ทธ๋ํ๋ฅผ ๊ฒน์ณ ๊ทธ๋ฆฌ๋ ค๋ฉด ๊ทธ๋ํ ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.scatterplot(x='total_bill', y='tip', data=df_tips)sns.rugplot(x='total_bill', y='tip', data=df_tips)
```




rugplot() ํจ์์ scatterplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํ
### 3\) ํ์คํ ๊ทธ๋จ: histplot()
Seaborn์์ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ํจ์๋ `histplot()`์
๋๋ค. `displot()` ํจ์๋ฅผ ์ด์ฉํด๋ ๋ฉ๋๋ค. Seaborn์์ `histplot()` ํจ์๋ก ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ(bivariate histogram)์ ๊ทธ๋ฆด ๋๋ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํฉ๋๋ค. ์ฌ๊ธฐ์๋ `histplot()` ๋์ `displot()`์ ์ด์ฉํด ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
#### ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ
```
pythonsns.histplot(x='flipper_length_mm', hue='species', data=df_penguins) # ์ฝ๋1# ๋๋sns.displot(x='flipper_length_mm', hue='species', data=df_penguins) # ์ฝ๋1
```
์ต์
์ ์ด์ฉํ๋ฉด ๋ค์ํ ์ข
๋ฅ์ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
> - hue: ๊ทธ๋ฃน๋ณ ํ์คํ ๊ทธ๋จ
> - multiple='stack': ๋์ ํ์คํ ๊ทธ๋จ(ํฌ๊ฐ์ง ์๊ณ ์๊ธฐ)
> - multiple='dodge': ๋ค์ค ํ์คํ ๊ทธ๋จ
```
pythonsns.displot(x='flipper_length_mm', hue='species',element='step', data=df_penguins) # ์ฝ๋2sns.displot(x='flipper_length_mm', hue='species',multiple='stack', data=df_penguins) # ์ฝ๋3sns.displot(x='flipper_length_mm', hue='sex',multiple='dodge', data=df_penguins) # ์ฝ๋4
```




displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ํ์คํ ๊ทธ๋จ1
```
pythonsns.displot(x='bill_length_mm', y='species', hue='species',legend=False, data=df_penguins)
```




displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ2
> - log\_scale=True: x์ถ ๊ฐ ๋ก๊ทธ ์ค์ผ์ผ๋ก ๋ณํ
> - element='poly': ๊ทธ๋ํ๋ฅผ ๋ถํฌ๋ค๊ฐํ(distribution polygon)์ผ๋ก ์ง์
> - fill=False: ๊ทธ๋ํ ์ ์๋ ์๊น ์ฑ์ฐ์ง ์๊ธฐ
```
pythonsns.displot(x='distance', hue='method', log_scale=True,element='poly', fill=False, data=df_planets)
```




displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ3
ํ ์บ๋ฒ์ค ๋ด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ์ง ์๊ณ ๊ทธ๋ํ๋ฅผ ์๋ก ๋ค๋ฅธ ์บ๋ฒ์ค์ ๋๋์ด์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `col` ์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `col` ์ต์
์ ๊ทธ๋ํ๋ฅผ ๊ฐ๋ณ ์บ๋ฒ์ค์ ๋๋์ด ๊ทธ๋ ค์ค๋๋ค.
```
pythonsns.displot(x='flipper_length_mm',col='sex', # ์ฑ๋ณ์ ๋ฐ๋ผ ์บ๋ฒ์ค ๊ตฌ๋ถdata=df_penguins)
```




displot ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ4
๋ง์ผ ๋ ๋ณ๋์ด ๋ชจ๋ ์์นํ์ด๋ผ๋ฉด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ์ ํํธ๋งต(heatmap) ๊ฐ์ ๋ชจ์์ ๋ ๊ฒ ๋ฉ๋๋ค.
> - binwidth: ์ง์ฌ๊ฐํ ํฌ๊ธฐ ์ง์
> - cbar: ์ ์ง์ค๋์ ๋ฐ๋ฅธ ๋น๋์๋ฅผ ๋ํ๋ด๋ ์ปฌ๋ฌ๋ฐ ์ ๋ฌด ์ง์
> - hue: ์์ผ๋ก ๊ตฌ๋ถ๋๋ ๊ทธ๋ฃน๋ณ ๊ทธ๋ํ ์ค์ (๋ถํฌ ๊ฐ ์ค๋ณต๋๋ ๋ถ๋ถ์ด ์ ์ด์ผ ํจ)
```
python# ์ฝ๋1: 2์ฐจ์ - ๊ธฐ๋ณธsns.displot(x='bill_length_mm', y='bill_depth_mm',data=df_penguins)# ์ฝ๋2: 2์ฐจ์ - ์ง์ฌ๊ฐํ ๋์ด ์กฐ์ sns.displot(x='bill_length_mm', y='bill_depth_mm', binwidth=(2, .5),data=df_penguins)# ์ฝ๋3: 2์ฐจ์ - ์ปฌ๋ฌ๋ฐ ์ ๋ฌด ์ง์ sns.displot(x='bill_length_mm', y='bill_depth_mm', cbar=True,data=df_penguins)# ์ฝ๋4: 3์ฐจ์ - ๊ทธ๋ฃน๋ณ ์์ผ๋ก ๋ถ๋ฅsns.displot(x='bill_length_mm', y='bill_depth_mm', hue='species',data=df_penguins)
```




displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค๋ณ๋ ํ์คํ ๊ทธ๋จ
> - bins: ๋ฑ๊ธ ์ ์ง์ ํ๊ธฐ
> - discrete: x์ถ ๋ผ๋ฒจ์ ๋ง๋ ์ค๊ฐ์ ์์น์ํค๊ธฐ(True)
> - pthresh: ์ ์ฒด ๋ฐ์ดํฐ ์ค์์ ํด๋น ๋น์จ(0~1)์ ์
ํฌ๋ช
์ฒ๋ฆฌํ๊ธฐ
> - pmax: ํฌํ๋ ์ต๋๊ฐ(0~1) ์ง์ ํ๊ธฐ
```
python# ์ฝ๋1: ํํ๋ก x์ y๋ณ์ ๋ค๋ฅด๊ฒ ์ง์ sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False), log_scale=(False, True))# ์ฝ๋2: ๊ด์ธก์น๊ฐ ์๋ ๋ถ๋ถ ์์ผ๋ก ํ์(ํฌ๋ช
ํ๊ฒ ํ์ํ์ง ์๊ธฐ)sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),thresh=None)# ์ฝ๋3: ํ๊ณ์ ๊ณผ ํฌํ๋ ์ง์ sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),pthresh=.05, pmax=.9)# ์ฝ๋4: ์ปฌ๋ฌ๋งต ์ถ๊ฐsns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),cbar=True, cbar_kws=dict(shrink=.75))
```




displot() ํจ์์ ๋ค์ํ ์ต์
์ ์ ์ฉํ ํ์คํ ๊ทธ๋จ6
์ง๊ธ๊น์ง ์ฌ๋ฌ ๊ฐ์ง ์ต์
์ ์ด์ฉํด ๋ค์ํ ์ข
๋ฅ์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ ค๋ณด์์ต๋๋ค. ๋ง์ผ ๊ทธ๋ฃน๋ณ๋ก ๊ด์ธก์๊ฐ ๋ค๋ฅธ ํ์คํ ๊ทธ๋จ์ ๋น๊ตํ๊ณ ์ถ๋ค๋ฉด, ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ์ ๊ทํ(normalization)ํ๋ฉด ๋ฉ๋๋ค.
์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ(data point)๊ฐ ๋์ผํ ์ ๋์ ์ค์ผ์ผ(์ค์๋)๋ก ํด์๋๋๋ก ๋ง๋๋ ๊ณผ์ ์
๋๋ค. ์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ์ ์ค์๋๋ฅผ ๊ท ๋ฑํ๊ฒ ๋ง๋ญ๋๋ค. ๋ฐ๋ผ์, ์ด์์น๋ฅผ ์ง๋ ํน์ ์์ฑ์ด ์ ์ฒด ์์ฑ์ฒ๋ผ ๋ํ๋๋ ์ผ๋ฐํ์ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ ์ ์์ต๋๋ค. ์ ๊ทํ๋ฅผ ๊ฑฐ์น ํ์คํ ๊ทธ๋จ์ ์ ๊ท ํ์คํ ๊ทธ๋จ(normalized histogram)์ด ๋ฉ๋๋ค.
์ ๊ทํ๋ฅผ ์ํ ์ค์ผ์ผ๋ง ๊ธฐ์ค์ ์ผ๋ก๋ ์ ์ฒด ๊ด์ธก์์ ๋ฉด์ ์ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋จผ์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค.
#### ์ ๊ท ํ์คํ ๊ทธ๋จ(์ ์ฒด ๊ด์ธก์)
Seaborn์์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด `histplot()` ํจ์ ๋๋ `displot()` ํจ์์ `stat='probability'` ๋๋ `stat='percent'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. `stat` ์ต์
์ `probability` ์ธ์๋ฅผ ์ฃผ๋ฉด y์ถ์ด ํ๋ฅ (probability)์ธ ๊ทธ๋ํ๊ฐ ๊ทธ๋ ค์ง๋๋ค. ๋ฐ๋ฉด, `percent` ์ต์
์ ์ฌ์ฉํ๋ฉด y์ถ์ด ๋ฐฑ๋ถ์จ(percent)์ธ ๊ทธ๋ํ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ์ ์์ ๊ฒฝ์ฐ ๋ง๋๋ค์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ๋ฉด 1์ด ๋๊ณ , ํ์์ ๊ฒฝ์ฐ์๋ 100์ด ๋ฉ๋๋ค. ์ด ์ต์
์ ์ถ๊ฐ๋ฉด ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
python# ์ฝ๋1: y์ถ์ด ๋น์จ์ธ ์ ๊ท ํ์คํ ๊ทธ๋จsns.histplot(x='flipper_length_mm', hue='species',stat='probability', data=df_penguins)# ์ฝ๋2: y์ถ์ด ๋ฐฑ๋ถ์จ์ธ ์ ๊ท ํ์คํ ๊ทธ๋จsns.histplot(x='flipper_length_mm', hue='species',stat='percent', data=df_penguins)
```




์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ
์ฌ๊ธฐ์ `commont_norm` ์ต์
์ `False`๋ก ์ง์ ํ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๊ฐ๋ณ ๊ทธ๋ฃน์ ๊ด์ธก์๋ก ์ ๊ทํํ ์ ์์ต๋๋ค. ์ด๋ ๋ง๋ค์ด์ง๋ ํ์คํ ๊ทธ๋จ์ ์๋ก ๋
๋ฆฝ์ ์
๋๋ค.
```
python# ์ฝ๋1: y์ถ์ด ํ๋ฅ ์ธ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จsns.histplot(x='flipper_length_mm', hue='species',stat='probability',common_norm=False, data=df_penguins)# ์ฝ๋1: y์ถ์ด ๋ฐฑ๋ถ์จ์ธ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จsns.histplot(x='flipper_length_mm', hue='species',stat='percent',common_norm=False, data=df_penguins)
```




์ ์ฒด๊ด์ธก์๋ก ์ ๊ทํ: ๊ฐ๋ณ ํ์คํ ๊ทธ๋จ
์ด๋ฒ์๋ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
#### ์ ๊ท ํ์คํ ๊ทธ๋จ(๋ฉด์ )
Seaborn์์ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด `stat='density'` ์ต์
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ์ต์
์ ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์น์ ๊ฐ์์ ๋ง๋ ๋๋น(width)์ ๊ณฑ์ผ๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด์ค๋๋ค. ์ด ํ์คํ ๊ทธ๋จ์์ y์ถ์ ๋ฐ๋(density)๊ฐ ๋๊ณ , ๊ฐ ๋ง๋์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ ํฉ์ 1์ด ๋ฉ๋๋ค. ๋ง์ผ, ๋
๋ฆฝ์ ์ธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `common_norms=False` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
python# ์ฝ๋1: y์ถ์ด ๋ฐ๋์ธ ์ ๊ท ํ์คํ ๊ทธ๋จsns.displot(df_penguins, x='flipper_length_mm', hue='species',stat='density')# ์ฝ๋2: y์ถ์ด ๋ฐ๋์ธ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จsns.displot(df_penguins, x='flipper_length_mm', hue='species',stat='density',common_norm=False)
```




๋ฉด์ ์ผ๋ก ์ ๊ทํ: ๊ธฐ๋ณธ ์ ๊ท ํ์คํ ๊ทธ๋จ ๋ฐ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จ
์ง๊ธ๊น์ง Seaborn์์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ๊ณผ 2๊ฐ์ง ์ข
๋ฅ์ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ ์ง๊ด์ ์
๋๋ค. ํ์คํ ๊ทธ๋จ์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋น ๋ฅด๊ณ ํ๋์ ํ์
ํ๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ฉด ์ข์ต๋๋ค.
ํ์ง๋ง ํ๊ณ๋ ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ผ๋ก ํ๋ฅ ๋ฐ๋ํจ์(Probability Density Function, PDF)๋ฅผ ๋ํ๋ด๋ฉด ์ ํํ์ง ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์์ ๋ฑ๊ธ์ ์๋ ์๋ฌด๋ฆฌ ๋ง๊ฒ ์ก์๋ ์ ํํ๊ธฐ ๋๋ฌธ์
๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋งค๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ํ์คํ ๊ทธ๋จ์ ๋ฑ๊ธ์ ๋ถ์ฐ์์ ์ด๋ค๋ณด๋ ํ์คํ ๊ทธ๋จ์ ๋ชจ์๋ ๊ณ๋จ๊ณผ ๊ฐ์ด ์ธํ๋ถํํ๊ฒ ๋ํ๋ฉ๋๋ค.
๋ํ, ํ์คํ ๊ทธ๋จ์์๋ ๋ฑ๊ธ์ ๊ฐ๊ฒฉ๊ณผ ๋ฐ์ดํฐ์ ์์ ์์น์ ๋ฐ๋ผ ํ์คํ ๊ทธ๋จ์ ๋ชจ์์ด ๋ฌ๋ผ์ง๋๋ค. ๋ฐ์ดํฐ์ ์ฐจ์(dimension)์ด ์ฆ๊ฐํ ์๋ก ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋ถ์ํ๊ฑฐ๋ ๋ชจ๋ธ์ ์ถ์ ํ๋๋ฐ ํ์ํ ํ๋ณธ ๋ฐ์ดํฐ์ ๊ฐ์๋ ๊ธฐํ๊ธ์์ ์ผ๋ก ์ฆ๊ฐํ๋ค๋ ๋จ์ ๋ ์์ต๋๋ค.
์ด๋ฌํ ํ์คํ ๊ทธ๋จ์ ๋จ์ ์ ๊ฐ์ ํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฐ๋ก ์ปค๋๋ฐ๋์ถ์ (Kernel Density Estimation, KDE)์
๋๋ค. ์ง๊ธ๋ถํฐ๋ ์ปค๋๋ฐ๋์ถ์ ์ด๋ ๋ฌด์์ธ์ง ๊ทธ๋ฆฌ๊ณ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด KDE ๊ณก์ ์ ๊ทธ๋ฆฌ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
### 4\) ์ปค๋๋ฐ๋ํจ์ ๊ทธ๋ํ: kdeplot()
์ปค๋๋ฐ๋์ถ์ ์ด๋ ์ปค๋ ํจ์(kernel function)๋ฅผ ์ด์ฉํด์ ํ๋ฅ ๋ณ์์ ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ์ถ์ ํ๋ ๋น๋ชจ์์ (non-parametric) ํต๊ณ ๋ฐฉ๋ฒ์
๋๋ค. ๋น๋ชจ์์ ๋ฐฉ๋ฒ์ด๋ ๊ด์ธก ๋ฐ์ดํฐ๊ฐ ํน์ ํ๋ฅ ๋ถํฌ๋ฅผ ๋ฐ๋ฅธ๋ค๋ ์ ์ ์์ด ์ค์ํ๋ ๊ฒ์ ๋ฐฉ๋ฒ์
๋๋ค. ์ปค๋ ํจ์๋ ์์ ์ ์ค์ฌ์ผ๋ก ๋์นญ์ ์ด๋ฃจ๊ณ , ์์(non-negative) ์ค์(real-valued)๊ฐ์ ๊ฐ์ง๋ฉฐ, ์ ๋ถ๊ฐ์ด 1์ธ ํจ์(*K*)๋ฅผ ๋ปํฉ๋๋ค. ์ปค๋ ํจ์์๋ ๋ํ์ ์ผ๋ก ๊ฐ์ฐ์์(Gaussian), ์ฝ์ฌ์ธ(cosine), Epanechnikov ํจ์ ๋ฑ์ด ์์ต๋๋ค.




์ปค๋ํจ์ ์ข
๋ฅ
๋ฐ๋๊ทธ๋ฆผ(density plot)์ ์ปค๋ ์ค๋ฌด๋ฉ(kernel smoothing)์ ์ด์ฉํด ์ถ์ ํ ํ์คํ ๊ทธ๋จ์ ํ๋ฅ ๋ฐ๋ํจ์์
๋๋ค. KDE์์๋ ๋ฐ์ดํฐ๋ฅผ ์ปค๋ ํจ์๋ก ๋์นํ์ฌ ํ์คํ ๊ทธ๋จ์์ ๋ํ๋ฌ๋ ๋ฑ๊ธ์ ๋ถ์ฐ์์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค. KDE๋ก ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์
๋๋ค.
๋จ, KDE ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ๋๋ ์กฐ๊ฑด์ด ์์ต๋๋ค. KDE ๋ฐฉ๋ฒ์ ๊ทน๋จ๊ฐ์ด ์๋ ์ฐ์ ์๋ฃ์ ์ฌ์ฉํฉ๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ์ด์์น๊ฐ ์์ผ๋ฉด ํด๋น ๊ฐ์์ ํ๋ฅ ๋ฐ๋ํจ์๊ฐ ๋พฐ์กฑํ ๋ชจ์์ ๋ ๊ฒ ๋๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด์์น๊ฐ ์๋ ์ฐ์ ์๋ฃ์๋ KDE ๋ณด๋ค๋ ํ์คํ ๊ทธ๋จ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ํฉํฉ๋๋ค.
Seaborn์์ KDE ๋ฐฉ๋ฒ์ ํตํด ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `kdeplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `displot()` ํจ์์ `kind='kde'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ์ด๋ฒ์๋ `displot()` ํจ์์ `kind='kde'` ์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
> - multiple='stack': ๊ทธ๋ํ ์์์ ๊ทธ๋ฆฌ๊ธฐ
> - multiple='fill': ๊ฐ ๊ฐ์์ ๊ฒน์น ๋ถํฌ(stacked distribution) ์ ๊ทํํด์ ๊ทธ๋ฆฌ๊ธฐ(๋จ๋ณ๋์ผ ๋๋ง ์ ํจ, ๋ชจ๋ ๊ฐ์์ y์ถ์ ๋ฐ๋๊ฐ 1)
> - fill=True: ๊ทธ๋ํ ๋ถํฌ๋ช
ํ๊ฒ ๊ทธ๋ฆฌ๊ธฐ
> - cumulative=True: ๋์ ๋ถํฌํจ์ ๊ทธ๋ฆฌ๊ธฐ
```
python# ์ฝ๋1: ๊ธฐ๋ณธ ๊ทธ๋ํsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species')# ์ฝ๋2: ๊ทธ๋ํ ๊ฒน์ณ์ ๊ทธ๋ฆฌ๊ธฐsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',multiple='stack')# ์ฝ๋3: ๋ชจ๋ ๊ฐ์์ ๊ฒน์น ๋ถํฌ ์ ๊ทํํ๊ธฐsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',multiple='fill')# ์ฝ๋4: ๊ทธ๋ํ ๋ถํฌ๋ช
ํ๊ฒ ๊ทธ๋ฆฌ๊ธฐsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',fill=True) # sns.kdeplot์์๋ shade=True๋ ์ฌ์ฉ ๊ฐ๋ฅ# ์ฝ๋5: ๋์ ๋ถํฌํจ์(Cumulative Distribution Function, CDF) ๊ทธ๋ฆฌ๊ธฐsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',cumulative=True, common_norm=False, common_grid=True)# ์ฝ๋6sns.displot(df_penguins, x='flipper_length_mm', kind='kde',hue='species',fill=True, common_norm=False, palette='crest',alpha=.5, linewidth=0)
```




kdeplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๋ฐ๋๊ทธ๋ฆผ
์ด๋ณ๋ KDE ๊ทธ๋ํ๋ ๋ฑ๊ณ ์ (contours)์ผ๋ก ํํ๋ฉ๋๋ค. ๊ฐ ๋ฑ๊ณ ์ ์ ๋ฐ๋๊ฐ ๊ฐ์ ์ง์ (iso-proportions)์ ์ด์ ๊ฒ์
๋๋ค.
> - thresh: ๊ฐ์ฅ ๋ฎ์ ๋ ๋ฒจ์ ๋ฑ๊ณ ์ ํฌ๊ธฐ ์กฐ์
> - levels: ๋ฑ๊ณ ์ ๊ฐ์ ๋๋ ๋ชจ์
```
python# ์ฝ๋1: 2์ฐจ์ - ๊ธฐ๋ณธ ๊ทธ๋ํsns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde')# ์ฝ๋2: 2์ฐจ์ - ๋ฑ๊ณ ์ ํฌ๊ธฐ ๋ฐ ๊ฐ์ ์กฐ์ sns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',thresh=.2, levels=4)# ์ฝ๋3: 2์ฐจ์ - ๊ฐ๋ณ ๋ฑ๊ณ ์ ํฌ๊ธฐ ์ง์ sns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',levels=[.01, .05, .1, .7])# ์ฝ๋4: 3์ฐจ์ - ๊ทธ๋ฃน๋ณ ๊ทธ๋ํ ์์ผ๋ก ๊ตฌ๋ถsns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',hue='species') # fill=True ์ถ๊ฐํ๋ฉด ๋ฑ๊ณ ์ ์์ด ์์ผ๋ก ์ฑ์์ง
```




๋ค์ํ ๋ค๋ณ๋ KDE ๋ฑ๊ณ ์ ๊ทธ๋ํ
### 5\) ๊ฒฝํ์ ๋์ ๋ถํฌํจ์: ecdfplot()
๊ฒฝํ์ ๋์ ๋ถํฌํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `ecdfplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `displot()` ํจ์์ \`kind='ecdf' ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
> - hue\_order: \# ์ ์์ ์ง์
> - complementary=True: ์๋ณด ๋์ ๋ถํฌํจ์(complementary cumulative distribution function, CCDF) ๊ทธ๋ฆฌ๊ธฐ
```
python# ์ฝ๋1sns.displot(df_penguins, x='flipper_length_mm', kind='ecdf')# ์ฝ๋2sns.displot(df_penguins, x='flipper_length_mm', kind='ecdf',hue='species')# ์ฝ๋3sns.displot(data=df_planets, x='distance', hue='method',hue_order=['Radial Velocity', 'Transit'],log_scale=True, element='step', fill=False,cumulative=True, stat='density', common_norm=False)# ์ฝ๋4: ์๋ณด ๋์ ๋ถํฌํจ์ ๊ทธ๋ฆฌ๊ธฐsns.ecdfplot(data=df_penguins, x='bill_length_mm',hue='species', complementary=True)
```




ecdfplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๊ฒฝํ์ ๋์ ๋ถํฌํจ์
## ๋ค์ฐจ์ ๋ฐ์ดํฐ: ๊ด๊ณ
### 1\) ์ ๊ทธ๋ํ: lineplot()
์ ๊ทธ๋ํ๋ ์๊ฐ ๊ฒฝ๊ณผ์ ๋ฐ๋ฅธ ์ฐ์ํ ๋ณ์์ ๋ณ๋์ ๋ณด์ฌ์ฃผ๋ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `lineplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `relplot()` ํจ์์ `kind='line'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ๋ค์์ `flights` ๋ฐ์ดํฐ์์ ์ฐ๋ณ(x์ถ) ํ๊ท ํ์น๊ฐ ์(y์ถ)๋ฅผ ํํํ ๊ทธ๋ํ์
๋๋ค. ์์์ผ๋ก ํ์๋ ๋ถ๋ถ์ 95% ์ ๋ขฐ๊ตฌ๊ฐ์
๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',data=df_flights)
```




lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ1
์ฐ๋ณ(x์ถ) ์ด ํ์น๊ฐ์(y์ถ)๋ฅผ ํํํ๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',data=df_flights.groupby('year').sum())# ๋๋sns.relplot(x='year', y='passengers', kind='line',data=df_flights.groupby('year').sum())
```




lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ2
์๋ณ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด `hue`์ `style` ์ต์
์ ์ด์ฉํด ๋ฐ์ดํฐ๋ฅผ ์์๊ณผ ์คํ์ผ๋ก ๊ตฌ๋ถํด์ฃผ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',hue='month', style='month', data=df_flights)
```




lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ3
`pandas`์ `pivot()` ํจ์๋ฅผ ์ด์ฉํด ๋ง๋ ํ๋ฅผ ์ด์ฉํด๋ ์ ๊ทธ๋ํ์ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. `pivot()` ํจ์๋ `index`์ `columns` ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์ฑ์ ๊ฐ๊ฐ ํ
์ด๋ธ์ ํ๊ณผ ์ด๋ก ์ง์ ํด์ `values` ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์น๋ฅผ ํํํฉ๋๋ค.
```
pythonflights_pivot = df_flights.pivot(index='month', columns='year', values='passengers') # ๊ฐ ์ฐ๋์ ์๋ณ ํ์น๊ฐ ์flights_pivot# sns.lineplot(data=flights_pivot)
```




pandas์ pivot()ํจ์๋ก ๋ง๋ ์ฐ๋ณ, ์๋ณ ํ์น๊ฐ ํ
### 2\) ์ฐ์ ๋: scatterplot()
์ฐ์ ๋๋ ๋ ๋ฐ์ดํฐ์ ๊ด๊ณ๋ฅผ ์ ์ผ๋ก ํํํ๋ ๋ฐฉ๋ฒ์
๋๋ค. Seaborn์ผ๋ก ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `scatterplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `relplot()` ํจ์์ `kind='scatter'` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.scatterplot(x='bill_length_mm', y='bill_depth_mm', data=df_penguins)# ๋๋sns.relplot(df_penguins['bill_length_mm'], df_penguins['bill_depth_mm'], kind='scatter')
```




Seaborn์ผ๋ก ๊ทธ๋ฆฐ 2์ฐจ์ ์ฐ์ ๋: ๊ธฐ๋ณธ
์ด๋ฒ์๋ 3์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์ฐ์ ๋๋ก ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค. ์ด์ ์๋ ์ธ๊ธํ๋ฏ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋ `hue`, `col`, `size` ๋ฑ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ถ ์ง์ด ์ค ์ ์๋ ํ๋ผ๋ฏธํฐ๋ก ์๊ฐํํ๋ฉด ๋ฉ๋๋ค.
> - style: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
> - markers: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
> - size: ๋ง์ปค ํฌ๊ธฐ ์ง์
> - sizes: ๋ง์ปค ํฌ๊ธฐ์ ๋ฒ์ ์ง์
> - legend='full': ๋ชจ๋ ๋ฐ์ดํฐํฌ์ธํธ ๋ณด์ด๊ฒ ํ๊ธฐ
> - hue\_norm: ์์ ๋ฒ์ ์ง์
```
pythonsns.relplot(x='bill_length_mm', y='bill_depth_mm',hue='island',size='island',col='sex',palette=['gray', 'steelblue', 'g'], sizes=(75, 200),alpha=.5,kind='scatter',data=df_penguins)
```




Seaborn์ผ๋ก ๊ทธ๋ฆฐ 3์ฐจ์ ์ฐ์ ๋
### 3\) ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋: jointplot()
๊ฒฐํฉ๋ถํฌ(joint distribution)์ ์ฃผ๋ณ๋ถํฌ(marginal distribution)๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `jointplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `jointplot()`์ ์ถ ์์ค(axes-level) ํจ์์
๋๋ค.
```
python# ์ฝ๋1: 2์ฐจ์ - ์ฐ์ ๋ + ํ์คํ ๊ทธ๋จsns.jointplot(x='bill_length_mm', y='bill_depth_mm', data=df_penguins)# ์ฝ๋2: 3์ฐจ์ - ์ฐ์ ๋ + KDE ๋ฐ๋๊ณก์ sns.jointplot(x='bill_length_mm', y='bill_depth_mm', hue='species',data=df_penguins)
```




jointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋
`jointplot()` ํจ์์ `kind='kde'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ ๊ฐ์ ๋ถํฌ๋ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ์์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
python# ์ฝ๋3 - 2์ฐจ์sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='hist', # ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ(์ฌ๊ฐํ) ๊ทธ๋ฆฌ๊ธฐspace=0, # x์ถ, y์ถ ๊ณต๊ฐ 0์ผ๋ก ๋ง๋ค๊ธฐsize=5, ratio=4, # ํฌ๊ธฐ, ๋น์จ ์กฐ์ ํ๊ธฐdata=df_penguins)# ์ฝ๋4 - 2์ฐจ์sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='hex', # ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ(์ก๊ฐํ) ๊ทธ๋ฆฌ๊ธฐspace=0, # x์ถ, y์ถ ๊ณต๊ฐ 0์ผ๋ก ๋ง๋ค๊ธฐsize=5, ratio=4, # ํฌ๊ธฐ, ๋น์จ ์กฐ์ ํ๊ธฐdata=df_penguins)# ์ฝ๋5 - 2์ฐจ์sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='reg', # ์ ํํ๊ท์ , KDE ๋ฐ๋๊ณก์ ์ถ๊ฐspace=0, # x์ถ, y์ถ ๊ณต๊ฐ 0์ผ๋ก ๋ง๋ค๊ธฐsize=5, ratio=4, # ํฌ๊ธฐ, ๋น์จ ์กฐ์ ํ๊ธฐdata=df_penguins)# ์ฝ๋6 - 3์ฐจ์sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='kde', # KDE ๋ฐ๋๋ฑ๊ณ ์ , KDE ๋ฐ๋๊ณก์ ๊ทธ๋ฆฌ๊ธฐhue='species',space=0, # x์ถ, y์ถ ๊ณต๊ฐ 0์ผ๋ก ๋ง๋ค๊ธฐsize=5, ratio=4, # ํฌ๊ธฐ, ๋น์จ ์กฐ์ ํ๊ธฐdata=df_penguins)
```




jointplot() ํจ์์ kind ์ต์
์ ๋ํด ๊ทธ๋ฆฐ ๋ค์ํ ๊ทธ๋ํ
์ด๋ฐ์๋ ์๋ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ ์ด๋ค ๊ทธ๋ํ๊ฐ ๋์ค๋์ง ํ์ธํด ๋ณด์ธ์.
```
python# ์ฝ๋1sns.jointplot(x='bill_length_mm', y='bill_depth_mm',marker='+', s=100, marginal_kws=dict(bins=25, fill=False),height=5, ratio=2, marginal_ticks=True, data=df_penguins)# ์ฝ๋2g = sns.jointplot(x='bill_length_mm', y='bill_depth_mm')g.plot_joint(sns.kdeplot, color='r', zorder=0, levels=6)g.plot_marginals(sns.rugplot, color='r', height=-.15, clip_on=False, data=df_penguins)
```




jointplot() ํจ์์ ์ฌ๋ฌ ๊ทธ๋ํ ๊ฒน์ณ ๊ทธ๋ฆฌ๊ธฐ
๋ ๋ค์ํ ์ข
๋ฅ์ ๊ฒฐํฉ๋ถํฌ ๋ฐ ์ฃผ๋ณ๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ๊ทธ๋ํ ์์ค(figure-level) ์ธํฐํ์ด์ค์ธ `JointGrid`๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋ค์์ `JointGrid`๋ฅผ ์ด์ฉํด ํ์คํ ๊ทธ๋จ๊ณผ ๋ฐ์ค๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์ฝ๋์
๋๋ค.
```
python# ์ฝ๋1g = sns.JointGrid(data=df_penguins, x='bill_length_mm', y='bill_depth_mm')g.plot_joint(sns.scatterplot, s=100, alpha=.5, edgecolor='.2', linewidth=.5)g.plot_marginals(sns.histplot, kde=True)# ์ฝ๋2g = sns.JointGrid(data=df_penguins, x='bill_length_mm', y='bill_depth_mm')g.plot(sns.regplot, sns.boxplot)g.refline(x=45, y=16)
```




JointGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํ
### 4\) ์ฐ์ ๋ ํ๋ ฌ: pairplot()
์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix)์ ์ฌ๋ฌ ๋ณ์๋ค์ ๋ชจ๋ ๊ฐ๋ฅํ ์ด์ ์กฐํฉ์ ํ๋ ฌ ํํ๋ก ํํํ ๊ทธ๋ํ์
๋๋ค. ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `pairplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ํจ์๋ ๋ฐ์ดํฐ์
์ ๋ชจ๋ ์ซ์ํ ๋ณ์ ์์ ๋ํด ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ๋๊ฐ์ ์๋ ๊ฐ ๋ณ์์ ๋ถํฌ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํ์คํ ๊ทธ๋จ์ด๋ KDE ํ๋กฏ์ ๊ทธ๋ฆฝ๋๋ค.
```
python# ์ฝ๋1sns.pairplot(df_penguins)
```




pairplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
`corner=True` ์ต์
์ ์ถ๊ฐํ๋ฉด ์ฐ์ ๋ ํ๋ ฌ์ ์ ๋ฐ๋ง ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythonsns.pairplot(df_penguins, corner=True)
```




์ ๋ฐ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
์ํ๋ ํน์ ๋ณ์๋ฅผ ์ง์ ํด์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythonsns.pairplot(df_penguins,x_vars=['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm'],y_vars=['bill_length_mm', 'bill_depth_mm'])
```




ํน์ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins, kind='hist',height=2)
```




2์ฐจ์ ํ์คํ ๊ทธ๋จ ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins, kind='kde') # KDE ๊ณก์ ๊ทธ๋ฆฌ๊ธฐ
```




2์ฐจ์ kde ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins,plot_kws=dict(marker='+', linewidth=1), # ๋น๋๊ฐ์ ๋ฐฉํฅ์ ์๋ ๊ทธ๋ํ ์ต์
diag_kws=dict(fill=False)) # ๋๊ฐ์ ๋ฐฉํฅ์ ์๋ ๊ทธ๋ํ ์ต์
```




์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1
```
pythong = sns.pairplot(df_penguins, diag_kind='kde') # ๋๊ฐ์ ๊ทธ๋ํ๋ KDE ํจ์g.map_lower(sns.kdeplot, levels=4, color='.2') # KDE ๊ณก์ ์์ค๊ณผ ์ ์ง์ ํ๊ธฐ
```




์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2
3์ฐจ์ ์ด์์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๋ ค๋ฉด `hue` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.pairplot(df_penguins, hue='species',markers=['o', 's', 'D'], # ๋ง์ปค ์ง์ diag_kind='hist') # ๋๊ฐ์ ๋ฐฉํฅ์ ๋ค์ด๊ฐ ๊ทธ๋ํ: ํ์คํ ๊ทธ๋จ
```




3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1
```
pythonsns.pairplot(df_penguins,hue='species',size=2, aspect=1.8,plot_kws=dict(linewidth=0.5, alpha=0.3),diag_kind='kde',diag_kws=dict(shade=True))
```




3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2
๋ ์ธ๋ฐํ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ๊ทธ๋ํ ์์ค ์ธํฐํ์ด์ค์ธ `PairGrid` ํด๋์ค๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `PairGrid` ํด๋์ค๋ก๋ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ทธ๋ํ๋ฅผ ์ง์ ์ง์ ํ ์ ์์ต๋๋ค. ๋ค์์ `kdeplot()`๊ณผ `histplot()` ํจ์๋ฅผ ์ด์ฉํด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ๊ณผ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์
๋๋ค.
```
pythong = sns.PairGrid(df_penguins)g.map_upper(sns.histplot)g.map_lower(sns.kdeplot, fill=True)g.map_diag(sns.histplot, kde=True)
```




PairGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ์ฐ์ ๋ ํ๋ ฌ
### 5\) ์๊ดํ๋ ฌ: heatmap(), clustermap()
#### heatmap
ํํธ๋งต(heatmap)์ ๋ฐ์ดํฐ๋ฅผ ์์์ ๊ฐ๋๋ก ํํํ๋ 2์ฐจ์ ๊ทธ๋ํฝ ํํ ๋ฐฉ์์
๋๋ค. ํํธ๋งต์ ๋ณ๋ ๊ฐ ๊ด๊ณ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ด ์ข์ต๋๋ค. ํํธ๋งต์ผ๋ก๋ ๋ค์ํ ๊ด๊ณ๋ฅผ ํํํ ์ ์๋๋ฐ ์ฌ๊ธฐ์๋ ์๊ดํ๋ ฌ์ ํํํด๋ณด๊ฒ ์ต๋๋ค.
```
pythondf_wines = df_wines.sample(frac=1, random_state=7).reset_index(drop=True) # ์ํ ๋ฌด์์๋ก ๋ง๋ค๊ธฐcorr = df_wines.corr() # ์๊ดํ๋ ฌ ํ ๋ง๋ค๊ธฐsns.heatmap(round(corr,1),annot=True, # ์๊ด๊ณ์ ํ์fmt='.1f', # ์๊ด๊ณ์ ์์์ ์๋ฆฌcmap='coolwarm', # ์ปฌ๋ฌ๋งต ์์ ํ๋ ํธvmax=1.0, # ์๊ด๊ณ์ ์ต๋๊ฐvmin=-1.0, # ์๊ด๊ณ์ ์ต์๊ฐlinecolor='white', # ์
ํ
๋๋ฆฌ ์์linewidths=.05) # ์
๊ฐ๊ฒฉsns.set(rc={'figure.figsize':(10,7)}) # ๊ทธ๋ํ ํฌ๊ธฐ
```




heatmap() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ์๊ดํ๋ ฌ ํํธ๋งต
#### clustermap
ํด๋ฌ์คํฐ๋งต(clustermap)์ ๋ฐ์ดํฐ ์๊ฐํ ๊ธฐ๋ฒ ์ค ํ๋๋ก, ํํธ๋งต๊ณผ ๊ณ์ธต์ ํด๋ฌ์คํฐ๋ง์ ๊ฒฐํฉํ ํํ์
๋๋ค. Seaborn์ผ๋ก ํด๋ฌ์คํฐ๋งต์ ๊ทธ๋ฆฌ๋ ค๋ฉด `clustermap()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `clustermap()` ํจ์์๋ `heatmap()` ํจ์์ ๋ฌ๋ฆฌ `standard_sacle` ํ๋ผ๋ฏธํฐ๊ฐ ์์ด ํด๋ฌ์คํฐ๋งต์ ๋ฒ์๋ฅผ 0~1๋ก ์ ๊ทํํ ์ ์์ต๋๋ค.
```
pythoncorr = df_wines.corr() # ์๊ดํ๋ ฌ ํ ๋ง๋ค๊ธฐsns.clustermap(corr,cmap='coolwarm', # ์ปฌ๋ฌ๋งต ์์ ํ๋ ํธstandard_scale=1)
```




clustermap() ํจ์๋ก ๊ทธ๋ฆฐ ์๊ดํ๋ ฌ ํด๋ฌ์คํฐ๋งต
### 6\) ํ๊ท ๊ทธ๋ํ
Seaborn์ผ๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `regplot()` ๋๋ `lmplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋จผ์ `regplot()` ์ฌ์ฉ๋ฒ๋ถํฐ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
#### regplot
`regplot()` ํจ์๋ ์ฐ์ ๋์ ์ ํ ํ๊ท์ (linear regression line)์ ํจ๊ป ๊ทธ๋ ค์ฃผ๋ ํจ์์
๋๋ค. ์ ํ ํ๊ท์ ์ฃผ๋ณ ์์์ ์ ๋ขฐ๊ตฌ๊ฐ(95%)์ ๋ํ๋
๋๋ค.
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',data=df_penguins)
```




regplot()์ผ๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํ๊ท ๊ทธ๋ํ
์ฌ๊ธฐ์ `lowess=True` ์ต์
์ ์ถ๊ฐํ๋ฉด ํ๊ท์ ์ ์ ํ์ด ์๋๋ผ ์ค์ํ ๋ฐ์ดํฐ์ ๊ฐ์ค์น๋ฅผ ๋์ด๋ ๊ตญ์ ํ๊ท(local regression) ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฝ๋๋ค. `lowess`๋ `locally weighted robust scatterplot smoothing`์ ์ฝ์์
๋๋ค.
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',lowess=True,data=df_penguins)
```




๊ตญ์ ํ๊ท ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ
> - scatter\_kws: ์ ์์(facecolor, fc), ์ ํ
๋๋ฆฌ ์์(edgecolor, ec), ํฌ๊ธฐ(size, s), ํฌ๋ช
๋ ์ง์
> - color: ์ ์์ ์ง์
> - line\_kws: ์ ๊ตต๊ธฐ(linewidth, lw), ์ ์คํ์ผ(line style, ls), ํฌ๋ช
๋ ์ง์
> - ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95)
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',scatter_kws={'fc':'gray', 'ec':'gray', 's':50, 'alpha':0.3},color='r',line_kws={'lw':1.5, 'ls':'--','alpha':0.5},ci=90,data=df_penguins)
```




๋ค์ํ ์ต์
์ ์ ์ฉํ ํ๊ท ๊ทธ๋ํ
#### lmplot
`lmplot()` ์ญ์ `regplot()`๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ๋จ, `lmplot()`์ ๊ทธ๋ํ ์์ค(figure-level) ํจ์๋ก `FacetGrid`๋ฅผ ๋ง๋ญ๋๋ค. `lmplot()`์ ๊ทธ๋ํ ์์ค ํจ์์ด๊ธฐ ๋๋ฌธ์ `regplot()`์์์ ๋ฌ๋ฆฌ `hue` ๋๋ `col`์ต์
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
```
python# ์ฝ๋1sns.lmplot(x='bill_length_mm', y='bill_depth_mm',hue='species',data=df_penguins)# ์ฝ๋2sns.lmplot(x='bill_length_mm', y='bill_depth_mm',col='species',data=df_penguins)
```




lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ1
์ ์ฒด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ง๋ค๊ณ ์ถ๋ค๋ฉด ๋ค์ ์ฝ๋๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
> - truncate=False: ํ๊ท์ x์ถ ๋๊น์ง ํํํ์ง ์๊ธฐ
> - facet\_kws=dict(sharex=False, sharey=False): x์ถ, y์ถ ๊ณต์ ํ์ง ์๊ธฐ
> - line\_kws: ํ๊ท์ ์คํ์ผ ์ง์ ํ๊ธฐ
> - scatter\_kws: ์ฐ์ ๋ ์ ์คํ์ผ ์ง์ ํ๊ธฐ
```
pythong = sns.lmplot(x='bill_length_mm', y='bill_depth_mm',col='species', row='sex',height=4,truncate=False,line_kws={'color':'steelblue','linestyle':'--' },data=df_penguins)axes = g.axes # FacetGrid์์ AxesSubplots์ ์ถ์ถfor ax in axes.ravel(): # AxesSubplots์ ์ํํ์ฌ ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ๋ฐฐ๊ฒฝ์ผ๋ก ํํsns.regplot(x='bill_length_mm', y='bill_depth_mm',fit_reg=False, # ์ ์ฒด ํ๊ท์ ์จ๊ธฐ๊ธฐscatter_kws={'fc':'gray', 'ec':'none', 's':30, 'alpha':0.3},ax=ax,data=df_penguins)
```




lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ2
#### residplot
`resideplot()`์ ์ค์ ๋ฐ์ดํฐํฌ์ธํธ์ ํ๊ท์ ๊ณผ์ ์์ฐจ(residuals)๋ฅผ ํํํ๋ ํจ์์
๋๋ค.
```
pythonsns.residplot(x='bill_length_mm', y='bill_depth_mm',lowess=True,data=df_penguins)
```




resideplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ฐจ ๊ทธ๋ํ
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ๋ชจ๋ ์๊ณ ๋ง์ผ์
จ์ต๋๋ค.
## ์ฐธ๊ณ ๋ฌธํ
- \[1\] ๋คํฌํ๋ก๊ทธ๋๋จธ, ๏ฝขKernel Density Estimation(์ปค๋๋ฐ๋์ถ์ )์ ๋ํ ์ดํด๏ฝฃ, ๋คํฌํ๋ก๊ทธ๋๋จธ, "<https://darkpgmr.tistory.com/147>"
- \[2\] ์ด์ ํ, ๏ฝขseaborn regplot vs lmplot๏ฝฃ, Pega Devlog, "<https://jehyunlee.github.io/2022/06/06/Python-DS-103-snsreglmplot/>"
- \[3\] Dipanjan (DJ) Sarkar, ๏ฝขThe Art of Effective Visualization of Multi-dimensional Data๏ฝฃ, Towards Data Science, "<https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57>"
- \[4\] Rfriend, ๏ฝข\[Python\] ๋ชจ์์ดํฌ ๊ทธ๋ํ (Mosaic Chart)๏ฝฃ, Rfriend, "<https://rfriend.tistory.com/418>"
- \[5\] Seaborn, ๏ฝขseaborn.histplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.histplot.html>"
- \[6\] Seaborn, ๏ฝขseaborn.jointplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.jointplot.html>"
- \[7\] Seaborn, ๏ฝขseaborn.pairplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.pairplot.html>"
- \[8\] Statsmodels, ๏ฝขstatsmodels.graphics.mosaicplot.mosaic๏ฝฃ, Statsmodels, "<https://www.statsmodels.org/dev/generated/statsmodels.graphics.mosaicplot.mosaic.html>"
์ด์ ๊ธ
[ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)
๋ค์ ๊ธ
[ECharts ์ฌ์ฉ๋ฒ๊ณผ ์์ ](https://www.snugarchive.com/blog/echarts-tutorial/)
[ํ์ผ๋ก ๋์๊ฐ๊ธฐ](https://www.snugarchive.com/)
0 Comments
#### ์๊ฐ


์น ๊ฐ๋ฐ, ๋ฐ์ดํฐ ๋ถ์
- - [์ปดํจํฐ ๊ณผํ2](https://www.snugarchive.com/blog/category/computer-science/)
- [๊ธฐ์ด2](https://www.snugarchive.com/blog/category/computer-science/basic/)
- [๋ฐ์ดํฐ ๊ณผํ9](https://www.snugarchive.com/blog/category/data-science/)
- [๋ฐ์ดํฐ ์์ง1](https://www.snugarchive.com/blog/category/data-science/data-collection/)
- [๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ5](https://www.snugarchive.com/blog/category/data-science/data-preprocessing/)
- [๋ฐ์ดํฐ ์๊ฐํ3](https://www.snugarchive.com/blog/category/data-science/visualization/)
- [ํ๊ฒฝ ์ค์ 12](https://www.snugarchive.com/blog/category/environment-setup/)
- [๊ฐ๋ฐ12](https://www.snugarchive.com/blog/category/environment-setup/development/)
- [์ํ1](https://www.snugarchive.com/blog/category/mathematics/)
- [ํต๊ณ1](https://www.snugarchive.com/blog/category/mathematics/statistics/)
- [์์ฐ์ด7](https://www.snugarchive.com/blog/category/natural-language/)
- [์์ด5](https://www.snugarchive.com/blog/category/natural-language/english/)
- [ํ๊ตญ์ด2](https://www.snugarchive.com/blog/category/natural-language/korean/)
- [ํ๋ก๊ทธ๋๋ฐ ์ธ์ด4](https://www.snugarchive.com/blog/category/programming-language/)
- [C3](https://www.snugarchive.com/blog/category/programming-language/c/)
- [Kotlin1](https://www.snugarchive.com/blog/category/programming-language/kotlin/)
- [์น ๊ฐ๋ฐ6](https://www.snugarchive.com/blog/category/web-development/)
- [HTML2](https://www.snugarchive.com/blog/category/web-development/html/)
- [React4](https://www.snugarchive.com/blog/category/web-development/react/)
- - [์น ์ฑ2](https://www.snugarchive.com/blog/category/web-app/)
- [๋์๋ณด๋2](https://www.snugarchive.com/blog/category/web-app/dashboard/)
#### ํ๊ทธ
๋ฆฌ์คํธ ํผ์ณ๋ณด๊ธฐ
[C ๊ธฐ์ด(3)](https://www.snugarchive.com/tag/c-%EA%B8%B0%EC%B4%88/)
[ChartJS(1)](https://www.snugarchive.com/tag/chartjs/)
[ECharts(1)](https://www.snugarchive.com/tag/echarts/)
[Gatsby(1)](https://www.snugarchive.com/tag/gatsby/)
[HTML ๊ธฐ์ด(2)](https://www.snugarchive.com/tag/html-%EA%B8%B0%EC%B4%88/)
[HTML ์์(1)](https://www.snugarchive.com/tag/html-%EC%9A%94%EC%86%8C/)
[HTML ํ๊ทธ(1)](https://www.snugarchive.com/tag/html-%ED%83%9C%EA%B7%B8/)
[IDE(3)](https://www.snugarchive.com/tag/ide/)
[JDK(2)](https://www.snugarchive.com/tag/jdk/)
[Kotlin ๊ธฐ์ด(1)](https://www.snugarchive.com/tag/kotlin-%EA%B8%B0%EC%B4%88/)
[MySQL(1)](https://www.snugarchive.com/tag/mysql/)
[Node(2)](https://www.snugarchive.com/tag/node/)
[pandas ์ฌ์ฉ๋ฒ(5)](https://www.snugarchive.com/tag/pandas-%EC%82%AC%EC%9A%A9%EB%B2%95/)
[Python Pandas ๊ธฐ์ด(4)](https://www.snugarchive.com/tag/python-pandas-%EA%B8%B0%EC%B4%88/)
[Python Seaborn(2)](https://www.snugarchive.com/tag/python-seaborn/)
[Python ์ค์ต(1)](https://www.snugarchive.com/tag/python-%EC%8B%A4%EC%8A%B5/)
[React(1)](https://www.snugarchive.com/tag/react/)
[React ๊ธฐ์ด(4)](https://www.snugarchive.com/tag/react-%EA%B8%B0%EC%B4%88/)
[React ์์(2)](https://www.snugarchive.com/tag/react-%EC%8B%9C%EC%9E%91/)
[React ์ ์(1)](https://www.snugarchive.com/tag/react-%EC%A0%95%EC%9D%98/)
[React ํ๊ฒฝ ์ค์ (1)](https://www.snugarchive.com/tag/react-%ED%99%98%EA%B2%BD-%EC%84%A4%EC%A0%95/)
[Spring(5)](https://www.snugarchive.com/tag/spring/)
[Visual Studio(1)](https://www.snugarchive.com/tag/visual-studio/)
[๊ฐ์ ํํ ์์ด(4)](https://www.snugarchive.com/tag/%EA%B0%90%EC%A0%95-%ED%91%9C%ED%98%84-%EC%98%81%EC%96%B4/)
[๋งํฌ์
์ธ์ด(1)](https://www.snugarchive.com/tag/%EB%A7%88%ED%81%AC%EC%97%85-%EC%96%B8%EC%96%B4/)
[์ด๊ฐ(2)](https://www.snugarchive.com/tag/%EC%96%B4%EA%B0%90/)
[์์ด ๋ฌธ๋ฒ ์ฉ์ด(1)](https://www.snugarchive.com/tag/%EC%98%81%EC%96%B4-%EB%AC%B8%EB%B2%95-%EC%9A%A9%EC%96%B4/)
[์์ด ์ฝ์ด(1)](https://www.snugarchive.com/tag/%EC%98%81%EC%96%B4-%EC%95%BD%EC%96%B4/)
[์์ด ์ค์๋ง(1)](https://www.snugarchive.com/tag/%EC%98%81%EC%96%B4-%EC%A4%84%EC%9E%84%EB%A7%90/)
[์ฃผํผํฐ ๋
ธํธ๋ถ(1)](https://www.snugarchive.com/tag/%EC%A3%BC%ED%94%BC%ED%84%B0-%EB%85%B8%ED%8A%B8%EB%B6%81/)
[ํฌ๋กค๋ง ์คํฌ๋ํ ์ฐจ์ด(1)](https://www.snugarchive.com/tag/%ED%81%AC%EB%A1%A4%EB%A7%81-%EC%8A%A4%ED%81%AC%EB%9E%98%ED%95%91-%EC%B0%A8%EC%9D%B4/)
[ํ
์คํธ ์๋ํฐ ์ถ์ฒ(1)](https://www.snugarchive.com/tag/%ED%85%8D%EC%8A%A4%ED%8A%B8-%EC%97%90%EB%94%94%ED%84%B0-%EC%B6%94%EC%B2%9C/)
[ํต๊ณ ๊ธฐ์ด(1)](https://www.snugarchive.com/tag/%ED%86%B5%EA%B3%84-%EA%B8%B0%EC%B4%88/)
[ํตํฉ ๊ฐ๋ฐ ํ๊ฒฝ(IDE) ์ถ์ฒ(1)](https://www.snugarchive.com/tag/%ED%86%B5%ED%95%A9-%EA%B0%9C%EB%B0%9C-%ED%99%98%EA%B2%BD\(ide\)-%EC%B6%94%EC%B2%9C/)
[ํ์ด์ฌ ๊ธฐ์ด(1)](https://www.snugarchive.com/tag/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EA%B8%B0%EC%B4%88/)
[ํ๋ก๊ทธ๋๋ฐ ๊ธฐ์ด(2)](https://www.snugarchive.com/tag/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-%EA%B8%B0%EC%B4%88/)
[ํ์ดํผํ
์คํธ(1)](https://www.snugarchive.com/tag/%ED%95%98%EC%9D%B4%ED%8D%BC%ED%85%8D%EC%8A%A4%ED%8A%B8/)
[ํ๊ตญ์ด๋ฅ๋ ฅ์ํ(2)](https://www.snugarchive.com/tag/%ED%95%9C%EA%B5%AD%EC%96%B4%EB%8A%A5%EB%A0%A5%EC%8B%9C%ED%97%98/)
[ํท๊ฐ๋ฆฌ๋ ํ๊ตญ์ด ๋จ์ด(2)](https://www.snugarchive.com/tag/%ED%97%B7%EA%B0%88%EB%A6%AC%EB%8A%94-%ED%95%9C%EA%B5%AD%EC%96%B4-%EB%8B%A8%EC%96%B4/)
#### ์ต๊ทผ๊ธ
[   ํ๊ฒฝ ์ค์ 2023-10-26 SQL Developer ๋ค์ด๋ก๋ ๋ฐ ์ฌ์ฉ๋ฒ](https://www.snugarchive.com/blog/sql-developer-setup/)
[   ํ๊ฒฝ ์ค์ 2023-08-31 DBMS ์ค์นํ๊ธฐ(์ค๋ผํด 21c XE, MySQL)](https://www.snugarchive.com/blog/dbms-installation/)
[   ํ๊ฒฝ ์ค์ 2023-08-21 STS 4/STS 3 ์ค์น ๋ฐ ํ๊ฒฝ ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/sts-setup/)
[   ํ๊ฒฝ ์ค์ 2023-08-21 ์ํ์น ํฐ์บฃ(Apache Tomcat) ๋ค์ด๋ก๋ ๋ฐ ํ๊ฒฝ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/apache-tomcat-setup/)
[   ๋ฐ์ดํฐ ๊ณผํ 2023-08-04 ECharts ์ฌ์ฉ๋ฒ๊ณผ ์์ ](https://www.snugarchive.com/blog/echarts-tutorial/)
#### ์ธ๊ธฐ๊ธ
[   ๋ฐ์ดํฐ ๊ณผํ 2022-04-19 ํ์ด์ฌ ์น ํฌ๋กค๋ง? ์น ์คํฌ๋ํ ๊ฐ๋
๊ณผ ์ค์ต ์์ ](https://www.snugarchive.com/blog/python-web-scraping/)
[   ํ๊ฒฝ ์ค์ 2022-04-14 ํตํฉ ๊ฐ๋ฐ ํ๊ฒฝ(IDE), ํ
์คํธ ์๋ํฐ ์ธ๊ธฐ ์์ (2022๋
)](https://www.snugarchive.com/blog/best-ide-text-editors/)
[   ํ๊ฒฝ ์ค์ 2023-08-21 ์ํ์น ํฐ์บฃ(Apache Tomcat) ๋ค์ด๋ก๋ ๋ฐ ํ๊ฒฝ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/apache-tomcat-setup/)
[   ํ๊ฒฝ ์ค์ 2022-04-16 ์ฃผํผํฐ ๋
ธํธ๋ถ ํ๊ฒฝ ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/jupyter-notebook-setup/)
[   ๋ฐ์ดํฐ ๊ณผํ 2022-06-05 ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)
#### ์ต๊ทผํ๋ก์ ํธ
[   ์น ์ฑ 2023-06-20 ์ง์ง ๋ชจ๋ํฐ๋ง ์ํฉํ ํ๋ก์ ํธ](https://www.snugarchive.com/blog/earthquake-dashboard/)
[   ์น ์ฑ 2021-12-01 ์ฝ๋ก๋19(COVID-19) ์ํฉํ ํ๋ก์ ํธ](https://www.snugarchive.com/blog/covid19-dashboard/)
#### ๋ชฉ์ฐจ
1. [์ค๋น](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EC%A4%80%EB%B9%84)
- [๊ธฐ๋ณธ ํ๊ฒฝ ์ค์ ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EA%B8%B0%EB%B3%B8-%ED%99%98%EA%B2%BD-%EC%84%A4%EC%A0%95)
- [๋ฐ์ดํฐ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8D%B0%EC%9D%B4%ED%84%B0)
2. [๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ๋ฒ์ฃผํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%8B%9C%EA%B0%81%ED%99%94-%EB%B2%94%EC%A3%BC%ED%98%95)
- [1\) ๋น๋ ๋ง๋๊ทธ๋ํ: countplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EB%B9%88%EB%8F%84-%EB%A7%89%EB%8C%80%EA%B7%B8%EB%9E%98%ED%94%84-countplot)
- [2\) ์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ: barplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%9A%94%EC%95%BD-%ED%86%B5%EA%B3%84%EB%9F%89-%EB%A7%89%EB%8C%80%EA%B7%B8%EB%9E%98%ED%94%84-barplot)
- [3\) ํฌ์ธํธ ํ๋กฏ: pointplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%ED%8F%AC%EC%9D%B8%ED%8A%B8-%ED%94%8C%EB%A1%AF-pointplot)
- [4\) ์์๊ทธ๋ฆผ: boxplot(), boxenplot(), violinplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%83%81%EC%9E%90%EA%B7%B8%EB%A6%BC-boxplot-boxenplot-violinplot)
- [5\) ๋ชจ์์ดํฌ ๊ทธ๋ํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EB%AA%A8%EC%9E%90%EC%9D%B4%ED%81%AC-%EA%B7%B8%EB%9E%98%ED%94%84)
3. [๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ์์นํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%8B%9C%EA%B0%81%ED%99%94-%EC%88%98%EC%B9%98%ED%98%95)
- [1\) ์ ๊ทธ๋ํ: stripplot(), swarmplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EC%A0%90%EA%B7%B8%EB%9E%98%ED%94%84-stripplot-swarmplot)
- [2\) ์ ๋ถ๊ทธ๋ํ: rugplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%84%A0%EB%B6%84%EA%B7%B8%EB%9E%98%ED%94%84-rugplot)
- [3\) ํ์คํ ๊ทธ๋จ: histplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%ED%9E%88%EC%8A%A4%ED%86%A0%EA%B7%B8%EB%9E%A8-histplot)
- [4\) ์ปค๋๋ฐ๋ํจ์ ๊ทธ๋ํ: kdeplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%BB%A4%EB%84%90%EB%B0%80%EB%8F%84%ED%95%A8%EC%88%98-%EA%B7%B8%EB%9E%98%ED%94%84-kdeplot)
- [5\) ๊ฒฝํ์ ๋์ ๋ถํฌํจ์: ecdfplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EA%B2%BD%ED%97%98%EC%A0%81-%EB%88%84%EC%A0%81%EB%B6%84%ED%8F%AC%ED%95%A8%EC%88%98-ecdfplot)
4. [๋ค์ฐจ์ ๋ฐ์ดํฐ: ๊ด๊ณ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EB%8B%A4%EC%B0%A8%EC%9B%90-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EA%B4%80%EA%B3%84)
- [1\) ์ ๊ทธ๋ํ: lineplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#1-%EC%84%A0%EA%B7%B8%EB%9E%98%ED%94%84-lineplot)
- [2\) ์ฐ์ ๋: scatterplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#2-%EC%82%B0%EC%A0%90%EB%8F%84-scatterplot)
- [3\) ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋: jointplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#3-%EA%B2%B0%ED%95%A9%EC%A3%BC%EB%B3%80%EB%B6%84%ED%8F%AC%EB%8F%84-jointplot)
- [4\) ์ฐ์ ๋ ํ๋ ฌ: pairplot()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#4-%EC%82%B0%EC%A0%90%EB%8F%84-%ED%96%89%EB%A0%AC-pairplot)
- [5\) ์๊ดํ๋ ฌ: heatmap(), clustermap()](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#5-%EC%83%81%EA%B4%80%ED%96%89%EB%A0%AC-heatmap-clustermap)
- [6\) ํ๊ท ๊ทธ๋ํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#6-%ED%9A%8C%EA%B7%80-%EA%B7%B8%EB%9E%98%ED%94%84)
5. [์ฐธ๊ณ ๋ฌธํ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-advanced/#%EC%B0%B8%EA%B3%A0-%EB%AC%B8%ED%97%8C)
ยฉ2026 Snug Archive. All rights reserved.
Email: snugarchive@gmail.com |
| Readable Markdown | ## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ
Last Updated 2024-09-10 Published 2023-01-12[Python Seaborn](https://www.snugarchive.com/tag/python-seaborn/)11๋ถ
๋ชฉ์ฐจ

Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด๋ณด์
์ง๋ ์๊ฐ์๋ ํ์ด์ฌ์ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ๋ณ์๊ฐ 1๊ฐ์ธ ๋จ๋ณ๋ ๋ฐ์ดํฐ(univariate data)๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ ์๊ฐ์๋ ๋ณ์๊ฐ 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ(bivariate data)์ 3๊ฐ ์ด์์ธ ๋ค๋ณ๋ ๋ฐ์ดํฐ(multivariate data)๋ฅผ ์๊ฐํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค. Seaborn ์ฌ์ฉ์ ์ํ ๊ธฐ๋ณธ ํ๊ฒฝ ์ค์ ๋ฐฉ๋ฒ๊ณผ ๊ทธ๋ํ ์คํ์ผ๋ง, 1์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์ถ์ ๋ถ๋ค์ [ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)์ ๋จผ์ ์ฝ์ผ์๊ธฐ๋ฅผ ์ถ์ฒ๋๋ฆฝ๋๋ค.
๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๊ทธ๋ํ์ ์ข
๋ฅ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
1. ๋ค์ฐจ์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ ์๊ฐํ
> - ๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ): catplot(kind='count')
> - ๋น๋ ๋ง๋๊ทธ๋ํ(๋ค์ค, ๋์ ): countplot
> - ์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ: barplot
> - ์์ฝ ํต๊ณ๊ฐ ํฌ์ธํธ๊ทธ๋ํ: pointplot
> - ์์๊ทธ๋ฆผ: boxplot, boxenplot, violinplot
1. ๋ค์ฐจ์ ์์นํ ๋ฐ์ดํฐ ์๊ฐํ
> - ์ ๊ทธ๋ํ(dot plot): stripplot, swarmplot
> - ์ ๋ถ๊ทธ๋ํ(rug plot): rugplot
> - ํ์คํ ๊ทธ๋จ(histogram): histplot
> - ๋ฐ๋๊ทธ๋ฆผ(density plot): kdeplot
> - ๊ฒฝํ์ ๋์ ๋ถํฌํจ์(empirical cumulative distribution function): ecdfplot
1. ๋ค์ฐจ์ ๋ฐ์ดํฐ ๊ด๊ณ ์๊ฐํ
> - ์ ๊ทธ๋ํ(line plot): lineplot
> - ์ฐ์ ๋(scatter plot): scatterplot
> - ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋(joint/marginal distribution plot): jointplot
> - ์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix): pairplot
> - ์๊ด ํ๋ ฌ(correlation matrix): heatmap, clustermap
> - ํ๊ท ๊ทธ๋ํ(regression plot): regplot, lmplot, residplot

Seaborn ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ ๋ก๋๋งต
## ์ค๋น
์ค์ต์ ์ํด์๋ ๊ฐ๋ฐ ํ๊ฒฝ(development environments)๊ณผ ๋ฐ์ดํฐ๊ฐ ํ์ํฉ๋๋ค. ๋จผ์ ๊ฐ๋ฐ ํ๊ฒฝ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
### ๊ธฐ๋ณธ ํ๊ฒฝ ์ค์
๊ธ์์๋ ๊ฐ๋ฐ ํ๊ฒฝ์ผ๋ก ์ฃผํผํฐ ๋
ธํธ๋ถ(Jupyter notebook)์ ์ฌ์ฉํ์ต๋๋ค. ์ฌ๊ธฐ์๋ ์๊ฐํ ์ค์ต์ ํ๋๋ฐ ํ์ํ ์ต์ํ์ ์ค์ ๋ง ์ ์ฉํ๊ฒ ์ต๋๋ค. ์ฝ๋๋ณ ์์ธํ ์ค๋ช
์ Matplotlib ์ฌ์ฉ๋ฒ(์์ )์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฃผํผํฐ ๋
ธํธ๋ถ์ ์์ธํ ํ๊ฒฝ์ค์ ๋ฐฉ๋ฒ์ [์ฃผํผํฐ ๋
ธํธ๋ถ ํ๊ฒฝ ์ค์ ํ๊ธฐ](https://www.snugarchive.com/blog/jupyter-notebook-setup/)๋ฅผ ์ฐธ์กฐํ์๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib import rcParamsimport seaborn as snsimport warningsdef setting_styles_basic():rcParams['font.family'] = 'Malgun Gothic'rcParams['axes.unicode_minus'] = Falsesetting_styles_basic()warnings.filterwarnings('ignore')
```
๋ค์์ผ๋ก๋ ๊ทธ๋ํ์ ์ค์ผ์ผ(scale)์ ์กฐ์ ํ๊ฒ ์ต๋๋ค. ์ค์ผ์ผ ์กฐ์ ์ `sns.set_context` ํจ์๋ฅผ ์ด์ฉํด ์ค์ ํ ์ ์์ต๋๋ค. Seaborn์ ๋ค์ํ ์คํ์ผ๋ง ๋ฐฉ๋ฒ์ [ํ์ด์ฌ ๋ฐ์ดํฐ ์๊ฐํ Seaborn ์ฌ์ฉ๋ฒ ๊ธฐ์ดํธ](https://www.snugarchive.com/blog/python-data-visualization-seaborn-basic/)์ ์คํ์ผ๋ง ๋ถ๋ถ์ ์ฐธ์กฐํด ์ฃผ์ธ์. ์ฝ๋ ์คํ ๊ฒฐ๊ณผ๋ ๊ทธ๋ํ ์ ์ญ์ ์ ์ฉ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.set_context('paper',rc={'font.size':15,'xtick.labelsize':15,'ytick.labelsize':15,'axes.labelsize':15})
```
์ค์ต์ ์ํ ๊ธฐ๋ณธ์ ์ธ ํ๊ฒฝ ์ค์ ์ ๋ง์ณค๋ค๋ฉด ๋ค์์ ๋ฐ์ดํฐ๋ฅผ ์ค๋นํ ์ฐจ๋ก์
๋๋ค.
### ๋ฐ์ดํฐ
์ค์ต์ ์ํด์ Seaborn์ ๋ด์ฅ ๋ฐ์ดํฐ๋ฅผ `load_dataset()` ํจ์๋ฅผ ์ด์ฉํด ๋ก๋ฉํด ์ค๊ฒ ์ต๋๋ค. ํน์ ๋ฐ์ดํฐ์
์ Sklearn(์ฌ์ดํท๋ฐ)์์ ๋ถ๋ฌ์ pandas์ DataFrame์ผ๋ก ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค. ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythondf_titanic = sns.load_dataset('titanic')df_iris = sns.load_dataset('iris')df_penguins = sns.load_dataset('penguins')df_tips = sns.load_dataset('tips')df_diamonds = sns.load_dataset('diamonds')df_planets = sns.load_dataset('planets')df_flights = sns.load_dataset('flights')from sklearn.datasets import load_winewine_data = load_wine()df_wines = pd.DataFrame(data=wine_data.data,columns=wine_data.feature_names)
```
๊ทธ๋ผ ์ง๊ธ๋ถํฐ ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ ๋ณ๋์ด 2๊ฐ์ธ ์ด๋ณ๋ ๋ฐ์ดํฐ์ ๋ณ๋์ด 3๊ฐ ์ด์์ธ ๋ฐ์ดํฐ๋ฅผ ํฌํจํฉ๋๋ค. ๋ค๋ณ๋ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋ํ๋ก ํํํ ๋๋ ์์์ผ๋ก ๊ตฌ๋ถํ๋ `hue`, ์บ๋ฒ์ค๋ก ๊ตฌ๋ถํ๋ `col`, ์ ํฌ๊ธฐ๋ก ๊ตฌ๋ถํ๋ `size` ๋ฑ์ ํ๋ผ๋ฏธํฐ๋ฅผ ์ด์ฉํด ์๊ฐํ ์ฐจ์์ ๋ํ๋๊ฐ ์ ์์ต๋๋ค. ๋จผ์ ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค.
## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ๋ฒ์ฃผํ
๋ค๋ณ๋ ๋ฒ์ฃผํ ์๋ฃ๋ฅผ ์๊ฐํํ๋ Seaborn์ ๊ทธ๋ํ๋ ๋น๋ ๋ง๋๊ทธ๋ํ(๋ณ๋ ฌ, ๋ค์ค, ๋์ )๊ฐ ์์ต๋๋ค.
### 1\) ๋น๋ ๋ง๋๊ทธ๋ํ: countplot()
๋น๋ ๋ง๋๊ทธ๋ํ(์นด์ดํธํ๋กฏ)์ ๋ฒ์ฃผํ ๋ฐ์ดํฐ์ ๊ฐ์๋ฅผ ํํํฉ๋๋ค.
#### ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ
๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ ๋ ๋ณ๋์ ๋ํ ๋น๋ ๋ง๋๊ทธ๋ํ 2๊ฐ๋ฅผ ๊ฐ๊ฐ์ ์บ๋ฒ์ค(canvas)์ ๋ณ๋ ฌ๋ก ๋์ดํ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `catplot()` ํจ์์ `kind='count'` ์ `col` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. `countplot()` ํจ์๋ก๋ ๋ณ๋ ฌ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
```
pythonsns.catplot(x='class',col='who',kind='count',data=df_titanic)
```

countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ณ๋ ฌ ๋น๋ ๋ง๋๊ทธ๋ํ
#### ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ `countplot()` ๋๋ `catplot()`์ `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `hue` ์ต์
์ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํ๋ ํ๋ผ๋ฏธํฐ์
๋๋ค. ๋จผ์ ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ถํฐ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
##### ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
`countplot()` ํจ์ ๋๋ `caplot()` ํจ์๋ก ์์ง ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด ํด๋น ํจ์์ `x` ํ๋ผ๋ฏธํฐ์ ๊ฐ๋ก์ถ ๋ฒ์ฃผ๋ก ์ฌ์ฉํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๊ณ , `hue` ํ๋ผ๋ฏธํฐ์ ๋ค๋ฅธ ์์์ผ๋ก ๊ตฌ๋ถํ DataFrame์ ์ด ์ด๋ฆ์ ์
๋ ฅํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.countplot(x='class', hue='who', data=df_titanic)sns.catplot(x='class', hue='who', kind='count',palette='pastel',edgecolor='.6',data=df_titanic)
```

countplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ
`histplot()` ํจ์์ `multiple='dodge'` ์ต์
์ ์ฃผ์ด๋ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `histplot()` ํจ์๋ ์์นํ ์๋ฃ๋ฅผ ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ง๋ค ๋ ์ฌ์ฉํ๋ ํจ์์ด์ง๋ง, ํ์คํ ๊ทธ๋จ์ ๋ง๋ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ์ฃผ๊ณ x์ถ ๋๊ธ์ ์์ ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ผ๋ฐ ๋ง๋๊ทธ๋ํ์ฒ๋ผ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonax = sns.histplot(x='sex', hue='survived',multiple='dodge',shrink=.8,data=df_titanic)ax.tick_params(bottom=False)
```

histplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ
์ด๋ฒ์๋ ์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
##### ์ํ ๋ค์ค ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ์์ง ๋ค์ค ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ๋ ์ฌ์ฉํ ํจ์์ `x` ํ๋ผ๋ฏธํฐ ๋์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.countplot(y='class', hue='who', data=df_titanic)sns.catplot(y='class', hue='who', kind='count',palette='pastel', edgecolor='.6',data=df_titanic)
```

countplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ฐ๋ก ๊ทธ๋ฃนํ ๋ง๋๊ทธ๋ํ
#### ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
Seaborn์ผ๋ก ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๋ง๋ค๋ ค๋ฉด `histplot()` ํจ์์ `multiple='stack'` ์ต์
์ ์ฃผ๋ฉด ๋ฉ๋๋ค.
##### ์์ง ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
```
pythonax = sns.histplot(x='sex', hue='survived',multiple='stack',shrink=.8,data=df_titanic)ax.tick_params(bottom=False)
```

histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์์ง ๋์ ๋ง๋๊ทธ๋ํ
##### ์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ
์ํ ๋์ ๋น๋ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `x` ํ๋ผ๋ฏธํฐ ๋์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonax = sns.histplot(y='sex', hue='survived',multiple='stack',shrink=.8,palette='pastel',data=df_titanic);ax.tick_params(left=False)
```

histplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋จ์ ์ํ ๋์ ๋ง๋๊ทธ๋ํ
### 2\) ์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ: barplot()
์์ฝ ํต๊ณ๋ ๋ง๋๊ทธ๋ํ๋ ๋ฒ์ฃผํ ์๋ฃ์ ๋ํ ์์นํ ๋ฐ์ดํฐ๋ฅผ ๋ถํธ์คํธ๋ฉ ์ํ๋ง(์๋ณธ ๋ฐ์ดํฐ์ ๋์ผํ ํฌ๊ธฐ์ ์ํ์ ์ฌ๋ฌ ๋ฒ ๋ณต์ ์ถ์ถ)ํ์ฌ ์ป์ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ ๊ทธ ํ๊ท ์ ์ ๋ขฐ๊ตฌ๊ฐ(confidence interval)์ ๋ํ๋ธ ๋ง๋๊ทธ๋ํ์
๋๋ค. ์ ๋ขฐ๊ตฌ๊ฐ์ ๋ง๋ ์ ๊ฒ์ ์ ์ค์ฐจ ๋ง๋(error bar)๋ก ํํ๋ฉ๋๋ค. ์์ฝ ํต๊ณ๊ฐ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `barplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='bar'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก๋ ๋ณต์ ์ํ๋ง๋ ํ๋ณธ๋ค์ ํ๊ท ๊ณผ 95% ์ ๋ขฐ๊ตฌ๊ฐ์ด ํํ๋์ง๋ง `estimator` ํ๋ผ๋ฏธํฐ์ `ci` ํ๋ผ๋ฏธํฐ๋ก ๊ฐ๊ฐ ์์ฝ ํต๊ณ๊ฐ๊ณผ ์ ๋ขฐ๊ตฌ๊ฐ์ ์ง์ ํ ์ ์์ต๋๋ค. ์ต์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
> - estimator: ์ค์๊ฐ `np.median`, ํฉ๊ณ `np.sum` ๋ฑ
> - ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95), `sd`๋ก ์ค์ ์ ํ์คํธ์ฐจ(standard deviation)๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ, `None`์ผ๋ก ์ค์ ์ ์ค์ฐจ ๋ง๋ ์ ๊ฑฐ
> - n\_boot: ๋ถํธ์คํธ๋ฉ ์ํ๋ง ํ์(๊ธฐ๋ณธ๊ฐ: 1000)
๋จผ์ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๋ฒ๋ถํฐ ์์๋ณด๊ฒ ์ต๋๋ค.
#### ๊ธฐ๋ณธ
##### ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ
์์ง ํ๊ท ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill', data=df_tips)sns.catplot(x='day', y='total_bill', kind='bar', data=df_tips)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ง๋๊ทธ๋ํ
##### ์ํ ์์ฝ ๋ง๋๊ทธ๋ํ
๋ง์ผ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `barplot()` ํจ์์ `orient='h'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.barplot(x='total_bill', y='day', orient='h', data=df_tips)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ง๋๊ทธ๋ํ
#### ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
`barplot()` ํจ์์ `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ๋ฉด ์์์ผ๋ก ๊ตฌ๋ถ๋๋ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
##### ์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
๋ค์์ ๋ณ๋์ด 3๊ฐ์ธ ๋ฐ์ดํฐ๋ฅผ ์์ง ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ก ํํํ๋ ์์ ์ฝ๋์
๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill',hue='smoker', data=df_tips)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์์ง ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํ
##### ์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ
์ํ ๋ค์ค ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ผ๋ฉด `orient=h` ํ๋ผ๋ฏธํฐ๊ฐ์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.barplot(x='total_bill', y='day',hue='smoker', orient='h', data=df_tips)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ํ ์์ฝ ๋ค์ค ๋ง๋๊ทธ๋ํ
#### ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `barplot()` ํจ์์ `dodge=False`์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. Seaborn์์ ๋์ ๋ง๋๊ทธ๋ํ๋ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋์ ์ต๋๊ฐ ์์ ๋ค๋ฅธ ํ๊ท ๊ฐ์ ๋ํ๋ด๋ ๋ง๋๋ฅผ ์์์ ๋ง๋๋ ๊ฒ์ด ์๋๋ผ ๊ทธ๋ํ ์์ฒด๋ฅผ ์๋ก ๊ฒน์ณ์ ๊ทธ๋ฆฐ ๊ฒ์
๋๋ค.
```
pythonsns.barplot(x='day', y='total_bill',hue='smoker', dodge=False,data=df_tips)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ1
๋์ ์์ฝ ๋ง๋๊ทธ๋ํ๋ `barplot()` ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํด์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythons1 = sns.barplot(x='species', y='sepal_length',color='coral', ci=None, data=df_iris)s2 = sns.barplot(x='species', y='petal_length',color='powderblue', ci=None, data=df_iris)
```

barplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋์ ์์ฝ ๋ง๋๊ทธ๋ํ2
์ ๊ทธ๋ํ์์ ๋ง๋์ y์ถ๊ฐ(์์น ๋ ๋ถ๋ถ)์ ๊ฐ๊ฐ `sepal_length`์ ํ๊ท ๊ณผ `petal_length`์ ํ๊ท ์ ๋ํ๋
๋๋ค.
### 3\) ํฌ์ธํธ ํ๋กฏ: pointplot()
ํฌ์ธํธํ๋กฏ์ ๋ง๋๊ทธ๋ํ์ ๋์ผํ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋์ ํ๊ท ๊ฐ์ ๋ง๋ ๋์ ์ (point)์ผ๋ก ํํํฉ๋๋ค. ํฌ์ธํธํ๋กฏ์ `pointplot()` ํจ์๋ฅผ ์ฌ์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ํฌ์ธํธํ๋กฏ์ ํ ํ๋ฉด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๋น๊ตํ ๋ ์ ์ฉํฉ๋๋ค.
```
pythonsns.pointplot(x='day', y='total_bill', data=df_tips)sns.catplot(x='day', y='total_bill', kind='point', data=df_tips)
```

pointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํฌ์ธํธ ํ๋กฏ
๋ง์ผ ์ ๋ขฐ๊ตฌ๊ฐ์ด ์๋๋ผ ํ์คํธ์ฐจ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด `ci='sd'`๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ ๊ณผ ํฌ์ธํธ๋ฅผ ๋ค๋ฅธ ๋ชจ์์ผ๋ก ํํํ ์๋ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.pointplot(x='class', y='survived', hue='sex',palette={'male': 'g', 'female': 'm'},markers=['^', 'o'],linestyles=['-', '--'],data=df_titanic)
```

์ต์
์ ์ถ๊ฐํ ํฌ์ธํธ ํ๋กฏ
### 4\) ์์๊ทธ๋ฆผ: boxplot(), boxenplot(), violinplot()
์์๊ทธ๋ฆผ(๋ฐ์คํ๋กฏ)์ ๋ฐ์ดํฐ์ ๋ถ์๋ฅผ 5๊ฐ์ง ์์ฝ ์์น(five-number summary)๋ก ์ ๊ณตํ๋ ๋ํ์
๋๋ค.
> - ์ 3์ฌ๋ถ์์ (Q3): ์ ์ฒด ๋ฐ์ดํฐ ์ค ์์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
> - ์ 2์ฌ๋ถ์์ (Q2 ๋๋ ์ค์๊ฐ): ์ ์ฒด ๋ฐ์ดํฐ์ 50%์ ํด๋นํ๋ ๊ฐ(์ค์๊ฐ), ๋ฐ์ค ๋ด๋ถ์ ์ ์ผ๋ก ํ์
> - ์ 1์ฌ๋ถ์์ (Q1): ์ ์ฒด ๋ฐ์ดํฐ ์ค ํ์ 25%์ ํด๋นํ๋ ๊ฐ, ๋ฐ์ค์ ์๋์ชฝ ๊ฒฝ๊ณ์ ์ผ๋ก ํ์
> - ์ฌ๋ถ์ ๋ฒ์ (IQR): Q3 - Q1, ๋ฐ์ค์ ๋์ด๋ก ํํ
> - ์ต๋๊ฐ (Maximum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ํฐ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
> - ์ต์๊ฐ (Minimum): ์ด์์น๋ฅผ ์ ์ธํ๊ณ ๋ฐ์ดํฐ์
์์ ๊ฐ์ฅ ์์ ๊ฐ, ๋ฐ์คํ๋กฏ์์ ์๋์ชฝ ์์ผ์ ๋์ ์ผ๋ก ํ์
> - ์ด์์น (Outliers): ์ผ๋ฐ์ ์ผ๋ก Q1 - 1.5IQR ๋ฏธ๋ง์ด๊ฑฐ๋ Q3 + 1.5IQR ์ด๊ณผ์ธ ๊ฐ๋ค์ ๊ฐ๋ณ ์ ์ผ๋ก ํ์
#### ๊ธฐ๋ณธ
Seaborn์์ ์์๊ทธ๋ฆผ์ ๋ง๋ค๋ ค๋ฉด `boxplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ 'kind='box'\` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.boxplot(data=df_iris)sns.catplot(data=df_iris, kind='box')
```

boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ง ์์๊ทธ๋ฆผ
๋ง์ผ ์์๊ทธ๋ฆผ์ ์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `orient='h'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.boxplot(data=df_iris, orient='h')
```

boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผ
3์ฐจ์ ๋ฐ์คํ๋กฏ์ `hue` ์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ฆด ์ ์์ต๋๋ค. `hue` ํ๋ผ๋ฏธํฐ๋ฅผ ๋ํ๋ฉด ๋น์ทํ ์์ฑ์ ๋ฐ์ดํฐ๋ผ๋ฆฌ ๋ถ๋ฅํ ์ ์์ต๋๋ค.
```
pythondf_tips['weekend'] = df_tips['day'].isin(['Sat', 'Sun'])sns.boxplot(x='total_bill', y='day', hue='weekend',orient='h',dodge=False,data=df_tips)
```

boxplot()์ผ๋ก ๊ทธ๋ฆฐ ์ํ ์์๊ทธ๋ฆผ2
#### ๋ฐ์จ ํ๋กฏ
๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ฌ ๊ฐ์ ๋ถ์๋ก ๋๋ ๋ฐ์คํ๋กฏ์
๋๋ค. ๋ฐ์จ ํ๋กฏ์ ๋ฐ์ดํฐ์
์ ๋ ๋ง์ ๋ถ์์(quantiles)๋ก ๋๋์ด ๊ธฐ์กด์ ์์๊ทธ๋ฆผ๋ณด๋ค ์ด์์น(outliers)์ ๋ํด ๋ ๋ง์ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ฐ๋ผ์, ๋ฐ์จ ํ๋กฏ์ ํฐ ๋ฐ์ดํฐ์
์ ์ฒ๋ฆฌํ๊ธฐ์ ์ ํฉํฉ๋๋ค.
๋ฐ์จ ํ๋กฏ์ ๋ง๋ค๋ ค๋ฉด `boxenplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='boxen'` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.boxenplot(x='color', y='price',data=df_diamonds.sort_values('color'))sns.catplot(x='color', y='price', kind='boxen',data=df_diamonds.sort_values('color'))
```

boxenplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์จ ํ๋กฏ
#### ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ
๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ์์๊ทธ๋ฆผ๊ณผ KDE ๋ฐฉ๋ฒ์ ์ด์ฉํด ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์(์ปค๋๋ฐ๋์ถ์ ํจ์)๋ฅผ ํฉ์น ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `violinplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `catplot()` ํจ์์ `kind='violin'` ์ต์
์ ์ถ๊ฐํด๋ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.
```
pythonsns.violinplot(x='total_bill', y='day', data=df_tips)sns.catplot(x='total_bill', y='day', kind='violin', data=df_tips)
```

violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ
์ด์ง ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด `hue` ์ `split=True` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.

violinplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ฐ์ด์ฌ๋ฆฐ ํ๋กฏ2
### 5\) ๋ชจ์์ดํฌ ๊ทธ๋ํ
๋ง๋๊ทธ๋ํ ์ธ์๋ ๋ณ๋์ด ๋ชจ๋ ๋ฒ์ฃผํ์ธ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋ ๋ชจ์์ดํฌ ๊ทธ๋ํ(mosaic plot)๋ฅผ ์ฌ์ฉํ๊ธฐ๋ ํฉ๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๊ทธ๋ฃน ๋ด์ ๋ฐ์ดํฐ ๋ฐฑ๋ถ์จ์ ๋ณด์ฌ์ฃผ๋ ๋์ ๋ง๋๊ทธ๋ํ์
๋๋ค. ๋ชจ์์ดํฌ ๊ทธ๋ํ๋ ๋ณ์๊ฐ 3๊ฐ ์ด์์ผ ๋๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ชจ์์ดํฌ ๊ทธ๋ํ๋ `statmodels.graphics.mosaic` ํจํค์ง์ `mosaic()` ํจ์๋ฅผ ์ด์ฉํด์ ๊ทธ๋ฆฝ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonfrom statsmodels.graphics.mosaicplot import mosaicimport matplotlib.pyplot as pltprops = lambda key: {'color': 'teal' if '1' in key else 'lightgray'}labelizer = lambda k: {('female','1'): '์ฌ์ฑ\n(์์กด)', ('female','0'): '์ฌ์ฑ\n(์ฌ๋ง)',('male','1'): '๋จ์ฑ\n(์์กด)', ('male', '0'): '๋จ์ฑ\n(์ฌ๋ง)'}[k]mosaic(df_titanic.sort_values('sex'),['sex', 'survived'],properties=props,labelizer=labelizer,axes_label=False)plt.title('ํ์ดํ๋ํธ ์ฑ๋ณ ์์กด์', fontsize=17)
```

mosaic ํจ์๋ก ๊ทธ๋ฆฐ ๋ชจ์์ดํฌ ํ๋กฏ
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ์ด๋ฒ์๋ ๋ค๋ณ๋ ์์นํ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
## ๋ค์ฐจ์ ๋ฐ์ดํฐ ์๊ฐํ: ์์นํ
### 1\) ์ ๊ทธ๋ํ: stripplot(), swarmplot()
์ ๊ทธ๋ํ๋ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ผ๋ก ๋ํ๋ธ ๋ํ์
๋๋ค. ์ ๊ทธ๋ํ๋ฅผ ์ด์ฉํ๋ฉด ๋ฐ์ดํฐ์ ์ค์ ์์น์ ๋ถํฌ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ต๋๋ค. Seaborn์์ ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ํจ์๋ `stripplot()`์
๋๋ค.
#### stripplot
```
pythonsns.stripplot(data=df_tips)sns.catplot(kind='strip', data=df_tips)
```

stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ
`stripplot()` ํจ์์ `jitter` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ผ๋ ฌ๋ก ๊ทธ๋ฆด ์ ์์ต๋๋ค.
> - jitter: ์งํฐ(jitter)๋ ๋ฐ์ดํฐ ๊ฐ์ ์ฝ๊ฐ์ ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ, ๋
ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฐ์ดํฐ ๊ฐ์ด ์กฐ๊ธ์ฉ ์์ง์ฌ์ ๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ ๋ฐ์ดํฐ๊ฐ ๊ทธ๋ํ์ ์ฌ๋ฌ ๋ฒ ๊ฒน์ณ์ ํ์๋๋ ํ์์ ๋ง์์ค
```
pythonsns.stripplot(x='total_bill', y='smoker',jitter=False,data=df_tips)
```

stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ2
๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์๋ก ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์งํ๋ ค๋ฉด `dodge=True` ์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
> - dodge=True: hue๋ก ๊ตฌ๋ถ๋ ๊ทธ๋ฃน ์ฌ์ด ๊ฐ๊ฒฉ์ ๋ง๋ค์ด ๋ฐ์ดํฐ๊ฐ ๊ฒน์น๋ ๊ฒ์ ๋ฐฉ์ง
```
pythonsns.stripplot(x='tip', y='day',palette='Spectral',dodge=True,data=df_tips)
```

stripplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ํ3
`dodge=True` ์ต์
์ฒ๋ผ ์ ๊ทธ๋ํ์์ ๋ฐ์ดํฐ ํฌ์ธํธ๋ค์ด ์๋ก ๊ฒน์น์ง ์๊ณ ์์ ๋ฌด๋ฆฌ์ฒ๋ผ ๋ณด์ด๊ฒ ๊ทธ๋ํ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ๋ ์์ต๋๋ค. ์ด๋ ์ฌ์ฉํ๋ ํจ์๊ฐ `swarmplot()`์
๋๋ค.
#### swarmplot
`swarmplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ์ ๋ํ์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ผ(swarm)์ฒ๋ผ ๋ฌด๋ฆฌ๋ฅผ ๋ง๋ค์ด ๋ฐ์ดํฐํฌ์ธํธ๊ฐ ์ค์ฒฉ๋๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค. ๋ผ ํ๋กฏ์ ๊ทธ๋ฆฌ๋ ๊ธฐ๋ณธ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.swarmplot(data=df_tips)sns.catplot(kind='swarm', data=df_tips)
```

swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ์ ์ฒด ๋ณ์
`x`์ `y` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ ๋ณ์์ ๋ํ ๋ผ ํ๋กฏ์ ๋ง๋ค ์ ์์ต๋๋ค.
```
pythonsns.swarmplot(x='day', y='total_bill', data=df_tips)sns.catplot(x='day', y='total_bill', kind='swarm', data=df_tips)
```

swarmplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ฐ์ดํฐํฌ์ธํธ ๋ถํฌ: ํน์ ๋ณ์
์ค์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ์ ์ด ์๋๋ผ ์ ๋ถ(rug)์ผ๋ก ํํํ ์๋ ์์ต๋๋ค.
### 2\) ์ ๋ถ๊ทธ๋ํ: rugplot()
์ค์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ์ ๋ถ์ผ๋ก ํํํ๊ณ ์ถ๋ค๋ฉด `rugplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `rugplot()`์ ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๊ฐ ์ถ ์์ ๋ณด์ฌ์ค๋๋ค.
```
pythonsns.rugplot(x='total_bill', y='tips', data='df_tips')
```

rugplot() ํจ์๋ก ๊ทธ๋ฆฐ ์ ๋ถ๊ทธ๋ํ
๋ณดํต ์ ๋ถ๊ทธ๋ํ๋ ๋ค๋ฅธ ๊ทธ๋ํ์ ํจ๊ป ๊ทธ๋ฆฝ๋๋ค. ๊ทธ๋ํ๋ฅผ ๊ฒน์ณ ๊ทธ๋ฆฌ๋ ค๋ฉด ๊ทธ๋ํ ํจ์๋ฅผ ์ฐ์ด์ด ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.scatterplot(x='total_bill', y='tip', data=df_tips)sns.rugplot(x='total_bill', y='tip', data=df_tips)
```

rugplot() ํจ์์ scatterplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํ
### 3\) ํ์คํ ๊ทธ๋จ: histplot()
Seaborn์์ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ํจ์๋ `histplot()`์
๋๋ค. `displot()` ํจ์๋ฅผ ์ด์ฉํด๋ ๋ฉ๋๋ค. Seaborn์์ `histplot()` ํจ์๋ก ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ(bivariate histogram)์ ๊ทธ๋ฆด ๋๋ ๋ณ๋์ ์์์ผ๋ก ๊ตฌ๋ถํฉ๋๋ค. ์ฌ๊ธฐ์๋ `histplot()` ๋์ `displot()`์ ์ด์ฉํด ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
#### ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ
```
pythonsns.histplot(x='flipper_length_mm', hue='species', data=df_penguins)sns.displot(x='flipper_length_mm', hue='species', data=df_penguins)
```
์ต์
์ ์ด์ฉํ๋ฉด ๋ค์ํ ์ข
๋ฅ์ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆด ์ ์์ต๋๋ค.
> - hue: ๊ทธ๋ฃน๋ณ ํ์คํ ๊ทธ๋จ
> - multiple='stack': ๋์ ํ์คํ ๊ทธ๋จ(ํฌ๊ฐ์ง ์๊ณ ์๊ธฐ)
> - multiple='dodge': ๋ค์ค ํ์คํ ๊ทธ๋จ
```
pythonsns.displot(x='flipper_length_mm', hue='species',element='step', data=df_penguins)sns.displot(x='flipper_length_mm', hue='species',multiple='stack', data=df_penguins)sns.displot(x='flipper_length_mm', hue='sex',multiple='dodge', data=df_penguins)
```

displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ํ์คํ ๊ทธ๋จ1
```
pythonsns.displot(x='bill_length_mm', y='species', hue='species',legend=False, data=df_penguins)
```

displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ2
> - log\_scale=True: x์ถ ๊ฐ ๋ก๊ทธ ์ค์ผ์ผ๋ก ๋ณํ
> - element='poly': ๊ทธ๋ํ๋ฅผ ๋ถํฌ๋ค๊ฐํ(distribution polygon)์ผ๋ก ์ง์
> - fill=False: ๊ทธ๋ํ ์ ์๋ ์๊น ์ฑ์ฐ์ง ์๊ธฐ
```
pythonsns.displot(x='distance', hue='method', log_scale=True,element='poly', fill=False, data=df_planets)
```

displot() ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ3
ํ ์บ๋ฒ์ค ๋ด์ ์ฌ๋ฌ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ์ง ์๊ณ ๊ทธ๋ํ๋ฅผ ์๋ก ๋ค๋ฅธ ์บ๋ฒ์ค์ ๋๋์ด์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `col` ์ต์
์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `col` ์ต์
์ ๊ทธ๋ํ๋ฅผ ๊ฐ๋ณ ์บ๋ฒ์ค์ ๋๋์ด ๊ทธ๋ ค์ค๋๋ค.
```
pythonsns.displot(x='flipper_length_mm',col='sex',data=df_penguins)
```

displot ํจ์๋ก ๊ทธ๋ฆฐ ํ์คํ ๊ทธ๋จ4
๋ง์ผ ๋ ๋ณ๋์ด ๋ชจ๋ ์์นํ์ด๋ผ๋ฉด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ์ ํํธ๋งต(heatmap) ๊ฐ์ ๋ชจ์์ ๋ ๊ฒ ๋ฉ๋๋ค.
> - binwidth: ์ง์ฌ๊ฐํ ํฌ๊ธฐ ์ง์
> - cbar: ์ ์ง์ค๋์ ๋ฐ๋ฅธ ๋น๋์๋ฅผ ๋ํ๋ด๋ ์ปฌ๋ฌ๋ฐ ์ ๋ฌด ์ง์
> - hue: ์์ผ๋ก ๊ตฌ๋ถ๋๋ ๊ทธ๋ฃน๋ณ ๊ทธ๋ํ ์ค์ (๋ถํฌ ๊ฐ ์ค๋ณต๋๋ ๋ถ๋ถ์ด ์ ์ด์ผ ํจ)
```
pythonsns.displot(x='bill_length_mm', y='bill_depth_mm',data=df_penguins)sns.displot(x='bill_length_mm', y='bill_depth_mm', binwidth=(2, .5),data=df_penguins)sns.displot(x='bill_length_mm', y='bill_depth_mm', cbar=True,data=df_penguins)sns.displot(x='bill_length_mm', y='bill_depth_mm', hue='species',data=df_penguins)
```

displot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค๋ณ๋ ํ์คํ ๊ทธ๋จ
> - bins: ๋ฑ๊ธ ์ ์ง์ ํ๊ธฐ
> - discrete: x์ถ ๋ผ๋ฒจ์ ๋ง๋ ์ค๊ฐ์ ์์น์ํค๊ธฐ(True)
> - pthresh: ์ ์ฒด ๋ฐ์ดํฐ ์ค์์ ํด๋น ๋น์จ(0~1)์ ์
ํฌ๋ช
์ฒ๋ฆฌํ๊ธฐ
> - pmax: ํฌํ๋ ์ต๋๊ฐ(0~1) ์ง์ ํ๊ธฐ
```
pythonsns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False), log_scale=(False, True))sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),thresh=None)sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),pthresh=.05, pmax=.9)sns.displot(df_planets, x='year', y='distance',bins=30, discrete=(True, False),log_scale=(False, True),cbar=True, cbar_kws=dict(shrink=.75))
```

displot() ํจ์์ ๋ค์ํ ์ต์
์ ์ ์ฉํ ํ์คํ ๊ทธ๋จ6
์ง๊ธ๊น์ง ์ฌ๋ฌ ๊ฐ์ง ์ต์
์ ์ด์ฉํด ๋ค์ํ ์ข
๋ฅ์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ ค๋ณด์์ต๋๋ค. ๋ง์ผ ๊ทธ๋ฃน๋ณ๋ก ๊ด์ธก์๊ฐ ๋ค๋ฅธ ํ์คํ ๊ทธ๋จ์ ๋น๊ตํ๊ณ ์ถ๋ค๋ฉด, ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ์ ์ ๊ทํ(normalization)ํ๋ฉด ๋ฉ๋๋ค.
์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ(data point)๊ฐ ๋์ผํ ์ ๋์ ์ค์ผ์ผ(์ค์๋)๋ก ํด์๋๋๋ก ๋ง๋๋ ๊ณผ์ ์
๋๋ค. ์ ๊ทํ๋ ๋ชจ๋ ๋ฐ์ดํฐ ํฌ์ธํธ์ ์ค์๋๋ฅผ ๊ท ๋ฑํ๊ฒ ๋ง๋ญ๋๋ค. ๋ฐ๋ผ์, ์ด์์น๋ฅผ ์ง๋ ํน์ ์์ฑ์ด ์ ์ฒด ์์ฑ์ฒ๋ผ ๋ํ๋๋ ์ผ๋ฐํ์ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ ์ ์์ต๋๋ค. ์ ๊ทํ๋ฅผ ๊ฑฐ์น ํ์คํ ๊ทธ๋จ์ ์ ๊ท ํ์คํ ๊ทธ๋จ(normalized histogram)์ด ๋ฉ๋๋ค.
์ ๊ทํ๋ฅผ ์ํ ์ค์ผ์ผ๋ง ๊ธฐ์ค์ ์ผ๋ก๋ ์ ์ฒด ๊ด์ธก์์ ๋ฉด์ ์ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋จผ์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค.
#### ์ ๊ท ํ์คํ ๊ทธ๋จ(์ ์ฒด ๊ด์ธก์)
Seaborn์์ ์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด `histplot()` ํจ์ ๋๋ `displot()` ํจ์์ `stat='probability'` ๋๋ `stat='percent'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. `stat` ์ต์
์ `probability` ์ธ์๋ฅผ ์ฃผ๋ฉด y์ถ์ด ํ๋ฅ (probability)์ธ ๊ทธ๋ํ๊ฐ ๊ทธ๋ ค์ง๋๋ค. ๋ฐ๋ฉด, `percent` ์ต์
์ ์ฌ์ฉํ๋ฉด y์ถ์ด ๋ฐฑ๋ถ์จ(percent)์ธ ๊ทธ๋ํ๊ฐ ๋ง๋ค์ด์ง๋๋ค. ์ ์์ ๊ฒฝ์ฐ ๋ง๋๋ค์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ๋ฉด 1์ด ๋๊ณ , ํ์์ ๊ฒฝ์ฐ์๋ 100์ด ๋ฉ๋๋ค. ์ด ์ต์
์ ์ถ๊ฐ๋ฉด ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค ์ ์์ต๋๋ค. ์์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.histplot(x='flipper_length_mm', hue='species',stat='probability', data=df_penguins)sns.histplot(x='flipper_length_mm', hue='species',stat='percent', data=df_penguins)
```

์ ์ฒด ๊ด์ธก์๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ
์ฌ๊ธฐ์ `commont_norm` ์ต์
์ `False`๋ก ์ง์ ํ๋ฉด ํ์คํ ๊ทธ๋จ์ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๊ฐ๋ณ ๊ทธ๋ฃน์ ๊ด์ธก์๋ก ์ ๊ทํํ ์ ์์ต๋๋ค. ์ด๋ ๋ง๋ค์ด์ง๋ ํ์คํ ๊ทธ๋จ์ ์๋ก ๋
๋ฆฝ์ ์
๋๋ค.
```
pythonsns.histplot(x='flipper_length_mm', hue='species',stat='probability',common_norm=False, data=df_penguins)sns.histplot(x='flipper_length_mm', hue='species',stat='percent',common_norm=False, data=df_penguins)
```

์ ์ฒด๊ด์ธก์๋ก ์ ๊ทํ: ๊ฐ๋ณ ํ์คํ ๊ทธ๋จ
์ด๋ฒ์๋ ์ ์ฒด ๊ด์ธก์๊ฐ ์๋๋ผ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
#### ์ ๊ท ํ์คํ ๊ทธ๋จ(๋ฉด์ )
Seaborn์์ ๋ฉด์ ์ผ๋ก ์ ๊ทํํ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค๋ ค๋ฉด `stat='density'` ์ต์
์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ์ต์
์ ๊ฐ ๋ฑ๊ธ์ ๋น๋์๋ฅผ ์ ์ฒด ๊ด์ธก์น์ ๊ฐ์์ ๋ง๋ ๋๋น(width)์ ๊ณฑ์ผ๋ก ๋๋ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋ค์ด์ค๋๋ค. ์ด ํ์คํ ๊ทธ๋จ์์ y์ถ์ ๋ฐ๋(density)๊ฐ ๋๊ณ , ๊ฐ ๋ง๋์ ๋์ด๋ฅผ ๋ชจ๋ ๋ํ ํฉ์ 1์ด ๋ฉ๋๋ค. ๋ง์ผ, ๋
๋ฆฝ์ ์ธ ํ์คํ ๊ทธ๋จ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `common_norms=False` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.displot(df_penguins, x='flipper_length_mm', hue='species',stat='density')sns.displot(df_penguins, x='flipper_length_mm', hue='species',stat='density',common_norm=False)
```

๋ฉด์ ์ผ๋ก ์ ๊ทํ: ๊ธฐ๋ณธ ์ ๊ท ํ์คํ ๊ทธ๋จ ๋ฐ ๊ฐ๋ณ ํ์คํ ๊ทธ๋จ
์ง๊ธ๊น์ง Seaborn์์ ๊ธฐ๋ณธ ํ์คํ ๊ทธ๋จ๊ณผ 2๊ฐ์ง ์ข
๋ฅ์ ์ ๊ท ํ์คํ ๊ทธ๋จ์ ๋ง๋๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ ์ง๊ด์ ์
๋๋ค. ํ์คํ ๊ทธ๋จ์ ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋น ๋ฅด๊ณ ํ๋์ ํ์
ํ๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ฉด ์ข์ต๋๋ค.
ํ์ง๋ง ํ๊ณ๋ ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์ผ๋ก ํ๋ฅ ๋ฐ๋ํจ์(Probability Density Function, PDF)๋ฅผ ๋ํ๋ด๋ฉด ์ ํํ์ง ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ์์ ๋ฑ๊ธ์ ์๋ ์๋ฌด๋ฆฌ ๋ง๊ฒ ์ก์๋ ์ ํํ๊ธฐ ๋๋ฌธ์
๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋งค๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ํ์คํ ๊ทธ๋จ์ ๋ฑ๊ธ์ ๋ถ์ฐ์์ ์ด๋ค๋ณด๋ ํ์คํ ๊ทธ๋จ์ ๋ชจ์๋ ๊ณ๋จ๊ณผ ๊ฐ์ด ์ธํ๋ถํํ๊ฒ ๋ํ๋ฉ๋๋ค.
๋ํ, ํ์คํ ๊ทธ๋จ์์๋ ๋ฑ๊ธ์ ๊ฐ๊ฒฉ๊ณผ ๋ฐ์ดํฐ์ ์์ ์์น์ ๋ฐ๋ผ ํ์คํ ๊ทธ๋จ์ ๋ชจ์์ด ๋ฌ๋ผ์ง๋๋ค. ๋ฐ์ดํฐ์ ์ฐจ์(dimension)์ด ์ฆ๊ฐํ ์๋ก ํ์คํ ๊ทธ๋จ์ผ๋ก ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ๋ถ์ํ๊ฑฐ๋ ๋ชจ๋ธ์ ์ถ์ ํ๋๋ฐ ํ์ํ ํ๋ณธ ๋ฐ์ดํฐ์ ๊ฐ์๋ ๊ธฐํ๊ธ์์ ์ผ๋ก ์ฆ๊ฐํ๋ค๋ ๋จ์ ๋ ์์ต๋๋ค.
์ด๋ฌํ ํ์คํ ๊ทธ๋จ์ ๋จ์ ์ ๊ฐ์ ํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฐ๋ก ์ปค๋๋ฐ๋์ถ์ (Kernel Density Estimation, KDE)์
๋๋ค. ์ง๊ธ๋ถํฐ๋ ์ปค๋๋ฐ๋์ถ์ ์ด๋ ๋ฌด์์ธ์ง ๊ทธ๋ฆฌ๊ณ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด KDE ๊ณก์ ์ ๊ทธ๋ฆฌ๋ ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
### 4\) ์ปค๋๋ฐ๋ํจ์ ๊ทธ๋ํ: kdeplot()
์ปค๋๋ฐ๋์ถ์ ์ด๋ ์ปค๋ ํจ์(kernel function)๋ฅผ ์ด์ฉํด์ ํ๋ฅ ๋ณ์์ ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ์ถ์ ํ๋ ๋น๋ชจ์์ (non-parametric) ํต๊ณ ๋ฐฉ๋ฒ์
๋๋ค. ๋น๋ชจ์์ ๋ฐฉ๋ฒ์ด๋ ๊ด์ธก ๋ฐ์ดํฐ๊ฐ ํน์ ํ๋ฅ ๋ถํฌ๋ฅผ ๋ฐ๋ฅธ๋ค๋ ์ ์ ์์ด ์ค์ํ๋ ๊ฒ์ ๋ฐฉ๋ฒ์
๋๋ค. ์ปค๋ ํจ์๋ ์์ ์ ์ค์ฌ์ผ๋ก ๋์นญ์ ์ด๋ฃจ๊ณ , ์์(non-negative) ์ค์(real-valued)๊ฐ์ ๊ฐ์ง๋ฉฐ, ์ ๋ถ๊ฐ์ด 1์ธ ํจ์(*K*)๋ฅผ ๋ปํฉ๋๋ค. ์ปค๋ ํจ์์๋ ๋ํ์ ์ผ๋ก ๊ฐ์ฐ์์(Gaussian), ์ฝ์ฌ์ธ(cosine), Epanechnikov ํจ์ ๋ฑ์ด ์์ต๋๋ค.

์ปค๋ํจ์ ์ข
๋ฅ
๋ฐ๋๊ทธ๋ฆผ(density plot)์ ์ปค๋ ์ค๋ฌด๋ฉ(kernel smoothing)์ ์ด์ฉํด ์ถ์ ํ ํ์คํ ๊ทธ๋จ์ ํ๋ฅ ๋ฐ๋ํจ์์
๋๋ค. KDE์์๋ ๋ฐ์ดํฐ๋ฅผ ์ปค๋ ํจ์๋ก ๋์นํ์ฌ ํ์คํ ๊ทธ๋จ์์ ๋ํ๋ฌ๋ ๋ฑ๊ธ์ ๋ถ์ฐ์์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค. KDE๋ก ์ถ์ ํ ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์
๋๋ค.
๋จ, KDE ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ๋๋ ์กฐ๊ฑด์ด ์์ต๋๋ค. KDE ๋ฐฉ๋ฒ์ ๊ทน๋จ๊ฐ์ด ์๋ ์ฐ์ ์๋ฃ์ ์ฌ์ฉํฉ๋๋ค. ํ๋ฅ ๋ฐ๋ํจ์๋ ๋ถ๋๋ฌ์ด ๊ณก์ ์ธ๋ฐ ์ด์์น๊ฐ ์์ผ๋ฉด ํด๋น ๊ฐ์์ ํ๋ฅ ๋ฐ๋ํจ์๊ฐ ๋พฐ์กฑํ ๋ชจ์์ ๋ ๊ฒ ๋๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด์์น๊ฐ ์๋ ์ฐ์ ์๋ฃ์๋ KDE ๋ณด๋ค๋ ํ์คํ ๊ทธ๋จ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ํฉํฉ๋๋ค.
Seaborn์์ KDE ๋ฐฉ๋ฒ์ ํตํด ํ๋ฅ ๋ฐ๋ํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `kdeplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `displot()` ํจ์์ `kind='kde'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ์ด๋ฒ์๋ `displot()` ํจ์์ `kind='kde'` ์ต์
์ ์ถ๊ฐํด์ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค.
> - multiple='stack': ๊ทธ๋ํ ์์์ ๊ทธ๋ฆฌ๊ธฐ
> - multiple='fill': ๊ฐ ๊ฐ์์ ๊ฒน์น ๋ถํฌ(stacked distribution) ์ ๊ทํํด์ ๊ทธ๋ฆฌ๊ธฐ(๋จ๋ณ๋์ผ ๋๋ง ์ ํจ, ๋ชจ๋ ๊ฐ์์ y์ถ์ ๋ฐ๋๊ฐ 1)
> - fill=True: ๊ทธ๋ํ ๋ถํฌ๋ช
ํ๊ฒ ๊ทธ๋ฆฌ๊ธฐ
> - cumulative=True: ๋์ ๋ถํฌํจ์ ๊ทธ๋ฆฌ๊ธฐ
```
pythonsns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species')sns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',multiple='stack')sns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',multiple='fill')sns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',fill=True)sns.displot(df_penguins, x='flipper_length_mm', kind='kde', hue='species',cumulative=True, common_norm=False, common_grid=True)sns.displot(df_penguins, x='flipper_length_mm', kind='kde',hue='species',fill=True, common_norm=False, palette='crest',alpha=.5, linewidth=0)
```

kdeplot() ํจ์๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๋ฐ๋๊ทธ๋ฆผ
์ด๋ณ๋ KDE ๊ทธ๋ํ๋ ๋ฑ๊ณ ์ (contours)์ผ๋ก ํํ๋ฉ๋๋ค. ๊ฐ ๋ฑ๊ณ ์ ์ ๋ฐ๋๊ฐ ๊ฐ์ ์ง์ (iso-proportions)์ ์ด์ ๊ฒ์
๋๋ค.
> - thresh: ๊ฐ์ฅ ๋ฎ์ ๋ ๋ฒจ์ ๋ฑ๊ณ ์ ํฌ๊ธฐ ์กฐ์
> - levels: ๋ฑ๊ณ ์ ๊ฐ์ ๋๋ ๋ชจ์
```
pythonsns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde')sns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',thresh=.2, levels=4)sns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',levels=[.01, .05, .1, .7])sns.displot(df_penguins, x='bill_length_mm', y='bill_depth_mm', kind='kde',hue='species')
```

๋ค์ํ ๋ค๋ณ๋ KDE ๋ฑ๊ณ ์ ๊ทธ๋ํ
### 5\) ๊ฒฝํ์ ๋์ ๋ถํฌํจ์: ecdfplot()
๊ฒฝํ์ ๋์ ๋ถํฌํจ์๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `ecdfplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `displot()` ํจ์์ \`kind='ecdf' ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
> - hue\_order: \# ์ ์์ ์ง์
> - complementary=True: ์๋ณด ๋์ ๋ถํฌํจ์(complementary cumulative distribution function, CCDF) ๊ทธ๋ฆฌ๊ธฐ
```
pythonsns.displot(df_penguins, x='flipper_length_mm', kind='ecdf')sns.displot(df_penguins, x='flipper_length_mm', kind='ecdf',hue='species')sns.displot(data=df_planets, x='distance', hue='method',hue_order=['Radial Velocity', 'Transit'],log_scale=True, element='step', fill=False,cumulative=True, stat='density', common_norm=False)sns.ecdfplot(data=df_penguins, x='bill_length_mm',hue='species', complementary=True)
```

ecdfplot()์ผ๋ก ๊ทธ๋ฆฐ ๋ค์ํ ๊ฒฝํ์ ๋์ ๋ถํฌํจ์
## ๋ค์ฐจ์ ๋ฐ์ดํฐ: ๊ด๊ณ
### 1\) ์ ๊ทธ๋ํ: lineplot()
์ ๊ทธ๋ํ๋ ์๊ฐ ๊ฒฝ๊ณผ์ ๋ฐ๋ฅธ ์ฐ์ํ ๋ณ์์ ๋ณ๋์ ๋ณด์ฌ์ฃผ๋ ๊ทธ๋ํ์
๋๋ค. Seaborn์ผ๋ก ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `lineplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `relplot()` ํจ์์ `kind='line'` ์ต์
์ ์ฃผ์ด๋ ๋ฉ๋๋ค. ๋ค์์ `flights` ๋ฐ์ดํฐ์์ ์ฐ๋ณ(x์ถ) ํ๊ท ํ์น๊ฐ ์(y์ถ)๋ฅผ ํํํ ๊ทธ๋ํ์
๋๋ค. ์์์ผ๋ก ํ์๋ ๋ถ๋ถ์ 95% ์ ๋ขฐ๊ตฌ๊ฐ์
๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',data=df_flights)
```

lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ1
์ฐ๋ณ(x์ถ) ์ด ํ์น๊ฐ์(y์ถ)๋ฅผ ํํํ๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',data=df_flights.groupby('year').sum())sns.relplot(x='year', y='passengers', kind='line',data=df_flights.groupby('year').sum())
```

lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ2
์๋ณ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ณ ์ถ๋ค๋ฉด `hue`์ `style` ์ต์
์ ์ด์ฉํด ๋ฐ์ดํฐ๋ฅผ ์์๊ณผ ์คํ์ผ๋ก ๊ตฌ๋ถํด์ฃผ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.lineplot(x='year', y='passengers',hue='month', style='month', data=df_flights)
```

lineplot()์ผ๋ก ๊ทธ๋ฆฐ ์ ๊ทธ๋ํ3
`pandas`์ `pivot()` ํจ์๋ฅผ ์ด์ฉํด ๋ง๋ ํ๋ฅผ ์ด์ฉํด๋ ์ ๊ทธ๋ํ์ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. `pivot()` ํจ์๋ `index`์ `columns` ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์ฑ์ ๊ฐ๊ฐ ํ
์ด๋ธ์ ํ๊ณผ ์ด๋ก ์ง์ ํด์ `values` ํ๋ผ๋ฏธํฐ์ ์ ๋ฌํ ์์น๋ฅผ ํํํฉ๋๋ค.
```
pythonflights_pivot = df_flights.pivot(index='month', columns='year', values='passengers')flights_pivot
```

pandas์ pivot()ํจ์๋ก ๋ง๋ ์ฐ๋ณ, ์๋ณ ํ์น๊ฐ ํ
### 2\) ์ฐ์ ๋: scatterplot()
์ฐ์ ๋๋ ๋ ๋ฐ์ดํฐ์ ๊ด๊ณ๋ฅผ ์ ์ผ๋ก ํํํ๋ ๋ฐฉ๋ฒ์
๋๋ค. Seaborn์ผ๋ก ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `scatterplot()` ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. `relplot()` ํจ์์ `kind='scatter'` ์ต์
์ ์ถ๊ฐํด๋ ๋ฉ๋๋ค.
```
pythonsns.scatterplot(x='bill_length_mm', y='bill_depth_mm', data=df_penguins)sns.relplot(df_penguins['bill_length_mm'], df_penguins['bill_depth_mm'], kind='scatter')
```

Seaborn์ผ๋ก ๊ทธ๋ฆฐ 2์ฐจ์ ์ฐ์ ๋: ๊ธฐ๋ณธ
์ด๋ฒ์๋ 3์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์ฐ์ ๋๋ก ์๊ฐํํด ๋ณด๊ฒ ์ต๋๋ค. ์ด์ ์๋ ์ธ๊ธํ๋ฏ ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ ๋๋ `hue`, `col`, `size` ๋ฑ ๋ฐ์ดํฐ๋ฅผ ๊ตฌ๋ถ ์ง์ด ์ค ์ ์๋ ํ๋ผ๋ฏธํฐ๋ก ์๊ฐํํ๋ฉด ๋ฉ๋๋ค.
> - style: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
> - markers: ๋ง์ปค ๋ชจ์ ์๋ ์ง์
> - size: ๋ง์ปค ํฌ๊ธฐ ์ง์
> - sizes: ๋ง์ปค ํฌ๊ธฐ์ ๋ฒ์ ์ง์
> - legend='full': ๋ชจ๋ ๋ฐ์ดํฐํฌ์ธํธ ๋ณด์ด๊ฒ ํ๊ธฐ
> - hue\_norm: ์์ ๋ฒ์ ์ง์
```
pythonsns.relplot(x='bill_length_mm', y='bill_depth_mm',hue='island',size='island',col='sex',palette=['gray', 'steelblue', 'g'], sizes=(75, 200),alpha=.5,kind='scatter',data=df_penguins)
```

Seaborn์ผ๋ก ๊ทธ๋ฆฐ 3์ฐจ์ ์ฐ์ ๋
### 3\) ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋: jointplot()
๊ฒฐํฉ๋ถํฌ(joint distribution)์ ์ฃผ๋ณ๋ถํฌ(marginal distribution)๋ฅผ ๊ทธ๋ฆฌ๋ ค๋ฉด `jointplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `jointplot()`์ ์ถ ์์ค(axes-level) ํจ์์
๋๋ค.
```
pythonsns.jointplot(x='bill_length_mm', y='bill_depth_mm', data=df_penguins)sns.jointplot(x='bill_length_mm', y='bill_depth_mm', hue='species',data=df_penguins)
```

jointplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ๊ฒฐํฉ/์ฃผ๋ณ๋ถํฌ๋
`jointplot()` ํจ์์ `kind='kde'` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ ๊ฐ์ ๋ถํฌ๋ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ์์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```
pythonsns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='hist',space=0,size=5, ratio=4,data=df_penguins)sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='hex',space=0,size=5, ratio=4,data=df_penguins)sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='reg',space=0,size=5, ratio=4,data=df_penguins)sns.jointplot(x='bill_length_mm', y='bill_depth_mm',kind='kde',hue='species',space=0,size=5, ratio=4,data=df_penguins)
```

jointplot() ํจ์์ kind ์ต์
์ ๋ํด ๊ทธ๋ฆฐ ๋ค์ํ ๊ทธ๋ํ
์ด๋ฐ์๋ ์๋ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ ์ด๋ค ๊ทธ๋ํ๊ฐ ๋์ค๋์ง ํ์ธํด ๋ณด์ธ์.
```
pythonsns.jointplot(x='bill_length_mm', y='bill_depth_mm',marker='+', s=100, marginal_kws=dict(bins=25, fill=False),height=5, ratio=2, marginal_ticks=True, data=df_penguins)g = sns.jointplot(x='bill_length_mm', y='bill_depth_mm')g.plot_joint(sns.kdeplot, color='r', zorder=0, levels=6)g.plot_marginals(sns.rugplot, color='r', height=-.15, clip_on=False, data=df_penguins)
```

jointplot() ํจ์์ ์ฌ๋ฌ ๊ทธ๋ํ ๊ฒน์ณ ๊ทธ๋ฆฌ๊ธฐ
๋ ๋ค์ํ ์ข
๋ฅ์ ๊ฒฐํฉ๋ถํฌ ๋ฐ ์ฃผ๋ณ๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ฒฝ์ฐ์๋ ๊ทธ๋ํ ์์ค(figure-level) ์ธํฐํ์ด์ค์ธ `JointGrid`๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋ค์์ `JointGrid`๋ฅผ ์ด์ฉํด ํ์คํ ๊ทธ๋จ๊ณผ ๋ฐ์ค๋ถํฌ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์ฝ๋์
๋๋ค.
```
pythong = sns.JointGrid(data=df_penguins, x='bill_length_mm', y='bill_depth_mm')g.plot_joint(sns.scatterplot, s=100, alpha=.5, edgecolor='.2', linewidth=.5)g.plot_marginals(sns.histplot, kde=True)g = sns.JointGrid(data=df_penguins, x='bill_length_mm', y='bill_depth_mm')g.plot(sns.regplot, sns.boxplot)g.refline(x=45, y=16)
```

JointGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ๊ทธ๋ํ
### 4\) ์ฐ์ ๋ ํ๋ ฌ: pairplot()
์ฐ์ ๋ ํ๋ ฌ(scatter plot matrix)์ ์ฌ๋ฌ ๋ณ์๋ค์ ๋ชจ๋ ๊ฐ๋ฅํ ์ด์ ์กฐํฉ์ ํ๋ ฌ ํํ๋ก ํํํ ๊ทธ๋ํ์
๋๋ค. ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `pairplot()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ์ด ํจ์๋ ๋ฐ์ดํฐ์
์ ๋ชจ๋ ์ซ์ํ ๋ณ์ ์์ ๋ํด ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฝ๋๋ค. ๋๊ฐ์ ์๋ ๊ฐ ๋ณ์์ ๋ถํฌ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํ์คํ ๊ทธ๋จ์ด๋ KDE ํ๋กฏ์ ๊ทธ๋ฆฝ๋๋ค.
```
pythonsns.pairplot(df_penguins)
```

pairplot() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
`corner=True` ์ต์
์ ์ถ๊ฐํ๋ฉด ์ฐ์ ๋ ํ๋ ฌ์ ์ ๋ฐ๋ง ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythonsns.pairplot(df_penguins, corner=True)
```

์ ๋ฐ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
์ํ๋ ํน์ ๋ณ์๋ฅผ ์ง์ ํด์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆด ์๋ ์์ต๋๋ค.
```
pythonsns.pairplot(df_penguins,x_vars=['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm'],y_vars=['bill_length_mm', 'bill_depth_mm'])
```

ํน์ 2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins, kind='hist',height=2)
```

2์ฐจ์ ํ์คํ ๊ทธ๋จ ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins, kind='kde')
```

2์ฐจ์ kde ์ฐ์ ๋ ํ๋ ฌ
```
pythonsns.pairplot(df_penguins,plot_kws=dict(marker='+', linewidth=1),diag_kws=dict(fill=False))
```

์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1
```
pythong = sns.pairplot(df_penguins, diag_kind='kde')g.map_lower(sns.kdeplot, levels=4, color='.2')
```

์ปค์คํ
2์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2
3์ฐจ์ ์ด์์ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๋ ค๋ฉด `hue` ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
```
pythonsns.pairplot(df_penguins, hue='species',markers=['o', 's', 'D'],diag_kind='hist')
```

3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ1
```
pythonsns.pairplot(df_penguins,hue='species',size=2, aspect=1.8,plot_kws=dict(linewidth=0.5, alpha=0.3),diag_kind='kde',diag_kws=dict(shade=True))
```

3์ฐจ์ ์ฐ์ ๋ ํ๋ ฌ2
๋ ์ธ๋ฐํ ์ฐ์ ๋ ํ๋ ฌ์ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ๊ทธ๋ํ ์์ค ์ธํฐํ์ด์ค์ธ `PairGrid` ํด๋์ค๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `PairGrid` ํด๋์ค๋ก๋ ๊ทธ๋ฆฌ๊ณ ์ถ์ ๊ทธ๋ํ๋ฅผ ์ง์ ์ง์ ํ ์ ์์ต๋๋ค. ๋ค์์ `kdeplot()`๊ณผ `histplot()` ํจ์๋ฅผ ์ด์ฉํด ์ด๋ณ๋ ํ์คํ ๊ทธ๋จ๊ณผ KDE ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ์์ ์
๋๋ค.
```
pythong = sns.PairGrid(df_penguins)g.map_upper(sns.histplot)g.map_lower(sns.kdeplot, fill=True)g.map_diag(sns.histplot, kde=True)
```

PairGrid ํด๋์ค๋ก ๊ทธ๋ฆฐ ์ฐ์ ๋ ํ๋ ฌ
### 5\) ์๊ดํ๋ ฌ: heatmap(), clustermap()
#### heatmap
ํํธ๋งต(heatmap)์ ๋ฐ์ดํฐ๋ฅผ ์์์ ๊ฐ๋๋ก ํํํ๋ 2์ฐจ์ ๊ทธ๋ํฝ ํํ ๋ฐฉ์์
๋๋ค. ํํธ๋งต์ ๋ณ๋ ๊ฐ ๊ด๊ณ๋ฅผ ํ๋์ ํ์
ํ ์ ์์ด ์ข์ต๋๋ค. ํํธ๋งต์ผ๋ก๋ ๋ค์ํ ๊ด๊ณ๋ฅผ ํํํ ์ ์๋๋ฐ ์ฌ๊ธฐ์๋ ์๊ดํ๋ ฌ์ ํํํด๋ณด๊ฒ ์ต๋๋ค.
```
pythondf_wines = df_wines.sample(frac=1, random_state=7).reset_index(drop=True)corr = df_wines.corr()sns.heatmap(round(corr,1),annot=True,fmt='.1f',cmap='coolwarm',vmax=1.0,vmin=-1.0,linecolor='white',linewidths=.05)sns.set(rc={'figure.figsize':(10,7)})
```

heatmap() ํจ์๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ์๊ดํ๋ ฌ ํํธ๋งต
#### clustermap
ํด๋ฌ์คํฐ๋งต(clustermap)์ ๋ฐ์ดํฐ ์๊ฐํ ๊ธฐ๋ฒ ์ค ํ๋๋ก, ํํธ๋งต๊ณผ ๊ณ์ธต์ ํด๋ฌ์คํฐ๋ง์ ๊ฒฐํฉํ ํํ์
๋๋ค. Seaborn์ผ๋ก ํด๋ฌ์คํฐ๋งต์ ๊ทธ๋ฆฌ๋ ค๋ฉด `clustermap()` ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. `clustermap()` ํจ์์๋ `heatmap()` ํจ์์ ๋ฌ๋ฆฌ `standard_sacle` ํ๋ผ๋ฏธํฐ๊ฐ ์์ด ํด๋ฌ์คํฐ๋งต์ ๋ฒ์๋ฅผ 0~1๋ก ์ ๊ทํํ ์ ์์ต๋๋ค.
```
pythoncorr = df_wines.corr()sns.clustermap(corr,cmap='coolwarm',standard_scale=1)
```

clustermap() ํจ์๋ก ๊ทธ๋ฆฐ ์๊ดํ๋ ฌ ํด๋ฌ์คํฐ๋งต
### 6\) ํ๊ท ๊ทธ๋ํ
Seaborn์ผ๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๊ณ ์ถ๋ค๋ฉด `regplot()` ๋๋ `lmplot()`์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค. ๋จผ์ `regplot()` ์ฌ์ฉ๋ฒ๋ถํฐ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
#### regplot
`regplot()` ํจ์๋ ์ฐ์ ๋์ ์ ํ ํ๊ท์ (linear regression line)์ ํจ๊ป ๊ทธ๋ ค์ฃผ๋ ํจ์์
๋๋ค. ์ ํ ํ๊ท์ ์ฃผ๋ณ ์์์ ์ ๋ขฐ๊ตฌ๊ฐ(95%)์ ๋ํ๋
๋๋ค.
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',data=df_penguins)
```

regplot()์ผ๋ก ๊ทธ๋ฆฐ ๊ธฐ๋ณธ ํ๊ท ๊ทธ๋ํ
์ฌ๊ธฐ์ `lowess=True` ์ต์
์ ์ถ๊ฐํ๋ฉด ํ๊ท์ ์ ์ ํ์ด ์๋๋ผ ์ค์ํ ๋ฐ์ดํฐ์ ๊ฐ์ค์น๋ฅผ ๋์ด๋ ๊ตญ์ ํ๊ท(local regression) ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฝ๋๋ค. `lowess`๋ `locally weighted robust scatterplot smoothing`์ ์ฝ์์
๋๋ค.
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',lowess=True,data=df_penguins)
```

๊ตญ์ ํ๊ท ๊ธฐ๋ฒ์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ
> - scatter\_kws: ์ ์์(facecolor, fc), ์ ํ
๋๋ฆฌ ์์(edgecolor, ec), ํฌ๊ธฐ(size, s), ํฌ๋ช
๋ ์ง์
> - color: ์ ์์ ์ง์
> - line\_kws: ์ ๊ตต๊ธฐ(linewidth, lw), ์ ์คํ์ผ(line style, ls), ํฌ๋ช
๋ ์ง์
> - ci: ์ ๋ขฐ๊ตฌ๊ฐ ์ง์ (๊ธฐ๋ณธ๊ฐ: 95)
```
pythonsns.regplot(x='bill_length_mm', y='bill_depth_mm',scatter_kws={'fc':'gray', 'ec':'gray', 's':50, 'alpha':0.3},color='r',line_kws={'lw':1.5, 'ls':'--','alpha':0.5},ci=90,data=df_penguins)
```

๋ค์ํ ์ต์
์ ์ ์ฉํ ํ๊ท ๊ทธ๋ํ
#### lmplot
`lmplot()` ์ญ์ `regplot()`๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ๊ท ๊ทธ๋ํ๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ๋จ, `lmplot()`์ ๊ทธ๋ํ ์์ค(figure-level) ํจ์๋ก `FacetGrid`๋ฅผ ๋ง๋ญ๋๋ค. `lmplot()`์ ๊ทธ๋ํ ์์ค ํจ์์ด๊ธฐ ๋๋ฌธ์ `regplot()`์์์ ๋ฌ๋ฆฌ `hue` ๋๋ `col`์ต์
์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
```
pythonsns.lmplot(x='bill_length_mm', y='bill_depth_mm',hue='species',data=df_penguins)sns.lmplot(x='bill_length_mm', y='bill_depth_mm',col='species',data=df_penguins)
```

lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ1
์ ์ฒด ๋ฐ์ดํฐํฌ์ธํธ๋ฅผ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ง๋ค๊ณ ์ถ๋ค๋ฉด ๋ค์ ์ฝ๋๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
> - truncate=False: ํ๊ท์ x์ถ ๋๊น์ง ํํํ์ง ์๊ธฐ
> - facet\_kws=dict(sharex=False, sharey=False): x์ถ, y์ถ ๊ณต์ ํ์ง ์๊ธฐ
> - line\_kws: ํ๊ท์ ์คํ์ผ ์ง์ ํ๊ธฐ
> - scatter\_kws: ์ฐ์ ๋ ์ ์คํ์ผ ์ง์ ํ๊ธฐ
```
pythong = sns.lmplot(x='bill_length_mm', y='bill_depth_mm',col='species', row='sex',height=4,truncate=False,line_kws={'color':'steelblue','linestyle':'--' },data=df_penguins)axes = g.axesfor ax in axes.ravel():sns.regplot(x='bill_length_mm', y='bill_depth_mm',fit_reg=False,scatter_kws={'fc':'gray', 'ec':'none', 's':30, 'alpha':0.3},ax=ax,data=df_penguins)
```

lmplot()์ผ๋ก ๊ทธ๋ฆฐ ํ๊ท ๊ทธ๋ํ2
#### residplot
`resideplot()`์ ์ค์ ๋ฐ์ดํฐํฌ์ธํธ์ ํ๊ท์ ๊ณผ์ ์์ฐจ(residuals)๋ฅผ ํํํ๋ ํจ์์
๋๋ค.
```
pythonsns.residplot(x='bill_length_mm', y='bill_depth_mm',lowess=True,data=df_penguins)
```

resideplot()์ผ๋ก ๊ทธ๋ฆฐ ์์ฐจ ๊ทธ๋ํ
์ง๊ธ๊น์ง Seaborn์ผ๋ก ๋ค์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋ฒ์ ์ดํด๋ณด์์ต๋๋ค. ๋ชจ๋ ์๊ณ ๋ง์ผ์
จ์ต๋๋ค.
## ์ฐธ๊ณ ๋ฌธํ
- \[1\] ๋คํฌํ๋ก๊ทธ๋๋จธ, ๏ฝขKernel Density Estimation(์ปค๋๋ฐ๋์ถ์ )์ ๋ํ ์ดํด๏ฝฃ, ๋คํฌํ๋ก๊ทธ๋๋จธ, "<https://darkpgmr.tistory.com/147>"
- \[2\] ์ด์ ํ, ๏ฝขseaborn regplot vs lmplot๏ฝฃ, Pega Devlog, "<https://jehyunlee.github.io/2022/06/06/Python-DS-103-snsreglmplot/>"
- \[3\] Dipanjan (DJ) Sarkar, ๏ฝขThe Art of Effective Visualization of Multi-dimensional Data๏ฝฃ, Towards Data Science, "<https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57>"
- \[4\] Rfriend, ๏ฝข\[Python\] ๋ชจ์์ดํฌ ๊ทธ๋ํ (Mosaic Chart)๏ฝฃ, Rfriend, "<https://rfriend.tistory.com/418>"
- \[5\] Seaborn, ๏ฝขseaborn.histplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.histplot.html>"
- \[6\] Seaborn, ๏ฝขseaborn.jointplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.jointplot.html>"
- \[7\] Seaborn, ๏ฝขseaborn.pairplot๏ฝฃ, Seaborn, "<https://seaborn.pydata.org/generated/seaborn.pairplot.html>"
- \[8\] Statsmodels, ๏ฝขstatsmodels.graphics.mosaicplot.mosaic๏ฝฃ, Statsmodels, "<https://www.statsmodels.org/dev/generated/statsmodels.graphics.mosaicplot.mosaic.html>"
์ด์ ๊ธ๋ค์ ๊ธ |
| Shard | 185 (laksa) |
| Root Hash | 15688750957463538185 |
| Unparsed URL | com,snugarchive!www,/blog/python-data-visualization-seaborn-advanced/ s443 |