- Categorical plots
- Joint plots
- Regression plots
- Matrixplots
- Heatmaps
- Customization of plots
자주 사용되는 seaborn Plots
- sns.lineplot(x='age', y='bmi', data=df)
- sns.scatterplot(x='age', y='bmi', data=df)
- sns.countplot(x='sex', data=df) : value_count (명목형)
- sns.stripplot(x='sex', data=df) : value_count (명목형)
- sns.boxplot(x='sex', y='bmi', data=df) : 4분위수 x: 명목형, y:연속형
- sns.swarmplot(data=df, x="sex", y="age", hue="survived")
- sns.violinplot(data=df, x="sex", y="age", hue="survived")
- sns.displot(x='sex', data=df, bins=50) x가 연속형변수, 히스토그램
- sns.histplot(x='sex', data=df, bins=50) x가 연속형변수, 히스토그램
- sns.barplot(data=df, x="sex", y="age", hue="survived")
- sns.jointplot(data=df, x="age", y="fare")
- sns.lmplot(data=df, x="age", y="fare") : scatter과 line을 같이 표시.
- sns.heatmap(df.corr(), annot=True) : 상관관계나, null 확인시
- sns.heatmap(df.isnull()) : 상관관계나, null 확인시
1. Categorical plots : 범주형 plot
countplot
stripplot
1) countplot
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("titanic.csv")
plt.figure(figsize=(5,3))
sns.countplot(data=df, x="pclass", hue="survived")
plt.show()
countplot는 범주형 변수의 빈도수를 시각화 하는 플롯이다.
df.groupby("pclass").survived.value_counts().unstack()
2)Stripplot
범주형 변수의 산점도를 시각화 하는 플롯이다.
영화에서 처럼 타이타닉의 여자와 아이먼저가 생존확률에 영향이 있음을 볼 수 있다.
sns.stripplot(data=df, x="sex", y="age", hue="survived", jitter=True)
plt.show()
3) Swarmplot
범주형 변수의 산점도를 시각화 하는 플롯으로 strip plot와 비슷한데 빈오가 많음을 시각적으로 좀더 표현해준다.
sns.swarmplot(data=df, x="sex", y="age", hue="survived")
plt.show()
4) Violinplot
범주형 변수의 산점도를 시각화 하는 플롯으로 swarm plot을 좀더 그래픽하게 표현하고 있다.
sns.violinplot(data=df, x="sex", y="age", hue="survived")
plt.show()
split=True로 옵션을 주면.
5) barplot
설명이 필요없는 bar plot이다. 일반적인 bar plo와 다르게 검은 직선이 있는데 신뢰구간(95%)을 의미한다.
sns.barplot(data=df, x="sex", y="age", hue="survived")
plt.show()
5) point plot
sns.pointplot(data=df, x="sex", y="age", hue="survived")
plt.show()
2. Jointplot / Regression
1) jointplot
scatter plot 과 히스토그램을 같이 표현할때 많이 사용된다.
sns.jointplot(data=df, x="age", y="fare")
plt.show()
2) lmplot
scatter와 회귀선을 표시하는 플롯이다.
선주변의 음영은 신뢰구간을 의미한다.
sns.lmplot(data=df, x="age", y="fare")
plt.show()
3. Matrixplot Heatmaps
1) heatmap
상관관계나 crosstab확인에 유용하다.
상관관계가 1에 가까울수록 밝은색으로, 상관관계가 -123에 가까울수록 어두운 색으로 표시된다.
sns.heatmap(df.corr(), annot=True)
plt.show()
'전처리' 카테고리의 다른 글
EDA 탐색적 데이터 분석 (0) | 2023.10.06 |
---|---|
feature_selection (변수 선택 법) (0) | 2023.08.03 |
시계열 데이터 (0) | 2023.07.07 |
Matplotlib 라이브러리 (0) | 2023.07.04 |
범주형데이터처리 - get_dummies, Label Encoder, OneHotEncoding (1) | 2023.06.22 |