목차
Seaborn
matlib에 얹어서 사용한다. 시각화 툴에 좋고, 통계 툴 사용에도 용이하다.
import matplotlib.pyplot as plt # 그래프 그리는 용도
import matplotlib.font_manager as fm # 폰트 관련 용도
import seaborn as sns
%matplotlib inline
# 현재 설치된 폰트 확인해보기
sys_font=fm.findSystemFonts()
print(f"sys_font number: {len(sys_font)}")
print(sys_font)
nanum_font = [f for f in sys_font if 'Nanum' in f]
print(f"nanum_font number: {len(nanum_font)}")
넘파이나 판다스처럼 기본적인 정보를 통계자료로 제공해준다.
df = sns.load_dataset("anscombe") #기본적인 데이터
df.head()

df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 44 entries, 0 to 43
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 dataset 44 non-null object
1 x 44 non-null float64
2 y 44 non-null float64
dtypes: float64(2), object(1)
memory usage: 1.2+ KB
df.describe()

모집단에서 표본집단으로 나누는 방법이 있다.
df1 = df[df['dataset'] =='I'] # 일부 데이터만 - 표본집단
df2 = df[df['dataset'] =='II']
df3 = df[df['dataset'] =='III']
df4 = df[df['dataset'] =='IV']
이런식으로 df1, df2, df3, df4의 각각의 산술통계를 구해볼 수도 있다.
sns.set()
- 환경변수 설정 함수 : set 함수는 스타일, 팔레트, 글꼴, 글꼴 크기 등 앞으로 그리게 되는 모든 플롯의 그림에 영향을 준다.
- seaborn.set(context, style, palette, font, font_scale, color_code, rc)
- Parameter
- context: 배율조정
- style: {None, 'darkgrid', 'whitegrid', 'dark', 'white', 'ticks'} 중 하나
lmplot(Logistic Model Plot)
lmplot을 사용하면, 산점도, 회귀선, 신뢰 구간을 표현해줄 수 있다.
sns.lmplot(x='x', y='y', data=df)
sns.lmplot(x='x', y='y', data=df, hue='dataset')

sns.lmplot(x='x', y='y', data=df, hue='dataset', col='dataset', col_wrap=2) # 전체 데이터의 분포

'col_wrap' 파라미터를 사용하면 그래프를 위의 그림처럼 펼쳐서 사용해 볼 수 있다.
sns.lmplot(x='x', y='y', data=df, hue='dataset', col='dataset', col_wrap=4, ci=None, palette="bright", height=4, scatter_kws={"s":50, "alpha":1})

'palette' 파라미터를 사용하면, 색깔도 지정할 수 있다.
'플레이데이터 빅데이터 부트캠프 12기 > Python' 카테고리의 다른 글
[플레이데이터 빅데이터 부트캠프]Python 데이터 시각화 PLOTLY(2) (0) | 2022.07.25 |
---|---|
[플레이데이터 빅데이터 부트캠프]Python 데이터 시각화 PLOTLY(1) (0) | 2022.07.25 |
[플레이데이터 빅데이터 부트캠프]Python 데이터 시각화(1) (0) | 2022.07.22 |
[플레이데이터 빅데이터 부트캠프]Python Pandas(3) (0) | 2022.07.21 |
[플레이데이터 빅데이터 부트캠프]Python Pandas(2) (0) | 2022.07.21 |