seaborn์ผ๋ก ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ
seaborn : ๊ฐํธํ๊ฒ ๊ทผ์ฌํ ๊ทธ๋ํ ์์ฑ
matplotlib : ์ํ๋๋๋ก ์ปค์คํ ํ๊ฒ ๊ทธ๋ํ ์์ฑ
์ฌ์ฉ ๋ฐฉ๋ฒ
์ผ๋ณ ๋ฐ์ดํฐ๋ก ์๋์ผ๋ก ํ๊ท ๊ฐ์ ๊ตฌํด month๋ก ๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค์ค
๋์์ธ
set_theme()ํจ์๋ก ๊ทธ๋ํ ์ปค์คํฐ๋ง์ด์งํ๊ธฐ
์ค์ต
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
bike_df = pd.read_csv('data/bike.csv')
sns.set_theme(rc={'figure.figsize': (10, 5)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.barplot(data=bike_df, x='quarter', y='registered', errorbar=None, hue='workingday')
๋ฐ์ดํฐ ๋ถํฌ ์๊ฐํ 1
stripplot
swarmplot
๋ง์ด ๋ถํฌ๋ ๊ณณ์ ๋๋ํ ์์ผ๋ก ๋์ค๊ฒ
stripplot, swarmplot : ๋ก์ฐ๊ฐ ์์ญ๊ฐ ~ ์๋ฐฑ๊ฐ ์ ๋ ๋๋ ๋น๊ต์ ์์ ๋ฐ์ดํฐ์ ์ ๋ถ์ํ ๋ ์ฌ์ฉ
์ค์ต
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
bike_df = pd.read_csv('data/bike.csv')
sns.set_theme(rc={'figure.figsize': (10, 5)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.stripplot(data=bike_df, x='month', y='temperature')
๋ฐ์ดํฐ ๋ถํฌ ์๊ฐํ 2
boxplot
order ๋ฅผ ์จ์ ์์ผ์ ์ ๋ ฌํ ์ ์๋ค.
violinplot
๋ฐ์ค ํ๋กฏ๊ณผ ๋ณด๋ ๋ฐฉ์์ด ๊ฑฐ์ ์ ์ฌํ๋ค.
ํฐ์ ์ด ์ค๊ฐ๊ฐ ๋๊บผ์ด ๋ง๋๊ฐ IQR
histplot
ํ๊ฐ์ง ๊ฐ์ ๋ํด ๋ถํฌ๋ฅผ ํ์ธํ๋ ๊ฒ์ด๋ฏ๋ก x๊ฐ๋ง ๋ฃ์
y๋ก ๋ฐ๊พธ๋ฉด ๊ฐ๋ก๋ก ๋์ด
multiple์ ์ฌ์ฉํ๋ฉด ์๋ ๋ง๋๊ทธ๋ํ์ ๊ฒน์ณ์ ๋์จ๋ค.
kdeplot
์ค์ต 1
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
flight_df = pd.read_csv('data/flight.csv')
sns.set_theme(rc={'figure.figsize': (6, 6)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.violinplot(data=flight_df, x='class', y='price')
plt.show()
์ค์ต 2
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
insurance_df = pd.read_csv('data/insurance_charge.csv')
sns.set_theme(rc={'figure.figsize': (10, 5)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.histplot(data=insurance_df, x='charge', hue='smoking', multiple='stack')
plt.show()
์๊ด๊ด๊ณ ์๊ฐํ
์ฐ์ ๋
์ด๋ค ๋ฐ์ดํฐ์ ์๊ด๊ด๊ณ ํ์ธ
์๊ด๊ณ์
์๊ด๊ด๊ณ๋ฅผ ์๋ก ํํํ ๊ฒ
ํผ์ด์จ ์๊ด๊ณ์ (-1 ~ 1)
์๊ด๊ณ์ = 0 ์ผ๋, ๋ ๊ฐ ์ฌ์ด์ ์๊ด ๊ด๊ณ๊ฐ ์๋ค.
์๊ด๊ณ์ > 0 ์ด๋ฉด, ์ด๋ค ๊ฐ์ด ์ปค์ง ๋ ๋ค๋ฅธ ๊ฐ๋ ํจ๊ป ์ปค์ง๋ค. (์์ ์๊ด๊ด๊ณ)
์๊ด๊ณ์ < 0 ์ด๋ฉด, ์ด๋ค ๊ฐ์ด ์ปค์ง ๋ ๋ค๋ฅธ ๊ฐ์ ์์์ง๋ค. (์์ ์๊ด๊ด๊ณ)
์๊ด๊ด๊ณ์ ๊ฐ๋
์๊ด๊ณ์๊ฐ ์ผ๋ง๋ ํฌ๊ฑฐ๋ ์์ ๊ฐ์ธ์ง ํ์ธ
๊ฐ์ด 1์ ๊ฐ๊น์ธ์๋ก ๊ฐํด์ง๊ณ 0์ ๊ฐ๊น์ธ์๋ก ์ฐ๊ด์ฑ์ด ์ฝํด์ง๋ค.
scatterplot
regplot
ํ๊ท์ : ๊ฐ์ด๋ฐ ์
๋ ๊ฐ์ ์๊ด๊ด๊ณ๋ฅผ ์์ฝํด์ ํํํ๋ ์ญํ
์ด์ ๊ทธ๋ํ์ ๋นํด ์๊ด๊ด๊ณ๊ฐ ์ฝํด๋ณด์ด๊ณ ์์ ์๊ด๊ด๊ณ ์ธ ๊ฒ ๊ฐ๋ค.
์๊ด๊ณ์๋ฅผ ํ์ธํ๋ ๋ฒ
total์ ๋ํ ์๊ด๊ณ์
์๊ด๊ณ์์ ๊ฐ ์ ๋ ฌ
์์ด ์งํ ์๋ก ์์ ๊ฐ, ์์ด ์ฐํ ์๋ก ๋์ ๊ฐ
์ค์ต 1
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
wine_df = pd.read_csv('data/wine.csv')
sns.set_theme(rc={'figure.figsize': (6, 6)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.regplot(data=wine_df, x='price', y='points')
plt.show()
์ค์ต 2
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
insurance_df = pd.read_csv('data/insurance_premium.csv')
sns.set_theme(rc={'figure.figsize': (8, 6)}, style='white')
# ์ฌ๊ธฐ์ ์ฝ๋๋ฅผ ์์ฑํ์ธ์.
sns.heatmap(insurance_df.corr(numeric_only=True),annot=True)
์ฝ๋์ 12 seaborn
'๋ง์ผํ > ๋ฐ์ดํฐ ๋ถ์' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ์ด์ฌ] ๋ฐ์ดํฐ ๋ค๋ฌ๊ธฐ (0) | 2025.03.13 |
---|---|
[ํ์ด์ฌ] DataFrame ๊ธฐ๋ณธ๊ธฐ (0) | 2025.03.13 |
[ํ์ด์ฌ] ํต๊ณ ๊ธฐ๋ณธ ์์๊ณผ ๊ทธ๋ํ (1) | 2025.03.09 |
[ํ์ด์ฌ] pandas (0) | 2025.02.25 |
[ํ์ด์ฌ] Matplotlib (1) | 2025.02.25 |