시각화
EDA-탐색적 데이터 분석¶
- 데이터를 이해하는 과정
시각화¶
- 데이터를 그래프적으로 보여주는 것
- 방대한 양의 자료를 분석하여 한눈에 볼 수 있도록 도표나 차트 등으로 정리하는 것
시각화 차트 5가지¶
- 순위 / 비교 : bar chart( 막대그래프 )
- 부분과 전체 : pie chart( 도넛차트 )
- 트랜트(추세) : line chart( 주식시장, 환율변동 등 )
- 상관관계 : 산포터(스캐터플롯(x,y좌표를 점으로 찍은것)), 히트맵(열과 행으로 색으로 표현) (나이가 증가함에 세포수는 줄어든다)
- 분포 : 히스토그램, box plot. (데이터들이 퍼저있는 정도)
Matplotlib¶
- https://matplotlib.org/ -> Tutorials
- https://matplotlib.org/ -> Tutorials -> 왼쪽에 pyplot tutorial
- 위의 내용에 matplotlib에 관련된 내용들이 있으니 참고하면 된다. 그리고 matplotlib의 pyplot를 사용하기 때문에 아래의 링크도 확인해보면 될 것이다. 수업중에 모든 내용을 다 할 수 없어 본인이 분석시 필요한 차트를 보고서 사용하면 될 것이다
- 우선적으로는 Matplotlib에 대해서 배우고 시본을 배울 것이다. 이유는 matplotlib의 진화된 형태가 시본이 된다. 그래서 matplotlib에 대해 먼저 배우도록 하자. 조금더 이쁘게 나오는게 시본이다.
In [ ]:
In [2]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# 경고 메세지를 숨겨주는 warnings
import warnings
warnings.filterwarnings("ignore")
In [3]:
# 한글 설정
plt.rc("font", family="Malgun Gothic")
# 시각화 기본 사이즈 정의
plt.rcParams["figure.figsize"] = (5, 3) #(가로, 세로)
In [4]:
x = [1,2,3,4,5,6,7,8,9,10]
y = [0, -0.5, -1.6 ,3 ,2.9 ,1.8 ,6, 6.4, 6.6, 10.4]
print(x)
y
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Out[4]:
[0, -0.5, -1.6, 3, 2.9, 1.8, 6, 6.4, 6.6, 10.4]
In [6]:
# line 형태로 출력
plt.plot(x, y)
Out[6]:
[<matplotlib.lines.Line2D at 0x193ab7db050>]
In [8]:
# 분포를 점으로 찍어서 출력
plt.scatter(x, y)
Out[8]:
<matplotlib.collections.PathCollection at 0x193abf3ec10>
In [9]:
# bar 차트로 출력
plt.bar(x, y)
Out[9]:
<BarContainer object of 10 artists>
In [ ]:
figure¶
- https://matplotlib.org/3.2.1/tutorials/introductory/usage.html
- figure : 그래프를 그리기 위한 틀
- axis : figure안에 그려질 틀의 속성을 지정하는 값
- axis가 가지고 있는 요소
- set_title : 그래프의 제목 부분
- gird : 틀을 바둑판 처럼 생성
- legend : 범례
- x axis label : 가로축 이름
- y axis label : 세로축 이름
- tick : 눈금
- tick label : 눈금에 글자
- major tick label : 긴 눈금이 들어가는 부분
- minor tick : 짧은 눈금
plt.subplots(nrows, ncols)¶
- plt.subplots를 사용하면 2개의 객체를 돌려준다
- figure, axis
In [13]:
data_1_x = [1,2,3]
data_1_y = [3,6,9]
data_2_x = [1,2,3]
data_2_y = [2,5,9]
plt.plot(data_1_x, data_1_y)
plt.plot(data_2_x, data_2_y)
# 타이틀(제목) 설정, 폰트 사이즈 설정
plt.title("타이틀 예시", fontsize=20)
Out[13]:
Text(0.5, 1.0, '타이틀 예시')
In [15]:
# 그래프의 크기를 다시 지정하여 출력
fig, ax = plt.subplots(figsize=(10, 3))
ax.plot(data_1_x, data_1_y)
ax.plot(data_2_x, data_2_y)
ax.set_title("타이틀")
Out[15]:
Text(0.5, 1.0, '타이틀')
In [17]:
plt.plot(data_1_x, data_1_y)
plt.plot(data_2_x, data_2_y)
plt.title("타이틀")
# x축을 90도 회전
plt.xticks(rotation=90)
# y축을 45도 회전
plt.yticks(rotation=45)
plt.show()
In [21]:
# 그래프의 크기를 다시 지정하여 출력
fig, ax = plt.subplots(figsize=(10, 3))
ax.plot(data_1_x, data_1_y)
ax.plot(data_2_x, data_2_y)
ax.set_title("타이틀")
ax.tick_params(axis="y", rotation=30)
ax.tick_params(axis="x", rotation=90)
In [20]:
plt.plot(data_1_x, data_1_y)
plt.plot(data_2_x, data_2_y)
plt.title("타이틀")
# 범례 설정
plt.legend(["legend1", "22222"], fontsize=10)
plt.show()
In [23]:
# 그래프의 크기를 다시 지정하여 출력
fig, ax = plt.subplots(figsize=(10, 3))
# 범례 이름 설정 1111, 2222
ax.plot(data_1_x, data_1_y, label='1111')
ax.plot(data_2_x, data_2_y, label='2222')
ax.set_title("타이틀")
# 범례 사이즈 설정
ax.legend(fontsize="20")
ax.tick_params(axis="y", rotation=30)
ax.tick_params(axis="x", rotation=90)
In [27]:
# 데이터를 1행, 2열로 출력
# 행 하나에 그래프가 2개 들어감
fg, ax = plt.subplots(1,2, figsize=(10,3))
ax[0].plot(data_1_x, data_1_y)
ax[1].scatter(x, y)
Out[27]:
<matplotlib.collections.PathCollection at 0x193af1d7c10>
In [28]:
# 데이터를 2행, 1열로 출력
# 행 하나에 그래프가 2개씩 2줄 들어감
fg, ax = plt.subplots(2,2, figsize=(10,3))
# 위치를 [][] 로 표시
ax[0][0].plot(x, y)
ax[1][1].scatter(x, y)
Out[28]:
<matplotlib.collections.PathCollection at 0x193af2d7c10>
In [30]:
# 데이터를 2행, 1열로 출력
# 행 하나에 그래프가 2개씩 2줄 들어감
fg, ax = plt.subplots(2,2, figsize=(10,3))
# 위치를 [][] 로 표시
ax[0][0].plot(x, y)
ax[1][1].scatter(x, y)
t_x = [10, 20, 30]
# pie 차트 출력
ax[0][1].pie(t_x, labels=["일", "이", "삼"])
h = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9]
ax[1][0].hist(h, bins=9)
Out[30]:
(array([2., 1., 1., 1., 1., 1., 1., 1., 1.]), array([1. , 1.88888889, 2.77777778, 3.66666667, 4.55555556, 5.44444444, 6.33333333, 7.22222222, 8.11111111, 9. ]), <BarContainer object of 9 artists>)
In [ ]:
In [ ]:
Seaborn ( https://seaborn.pydata.org/ )¶
- matplotlib을 기반으로 한 시각화 라이브러리
- 다양한 색상과 차트를 지원
- matplotlib보다 디자인적으로 우위를 가지고 있다
In [5]:
import seaborn as sns
In [6]:
# seaborn 에서 기본으로 제공해주는 dataset 인 tips
#지불한 총 요금, 팁, 성별, 흡연, 날짜, 시간, 사이즈를 가지고 있다
tips = sns.load_dataset('tips')
tips
Out[6]:
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
... | ... | ... | ... | ... | ... | ... | ... |
239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns
In [36]:
# 요일 확인
tips['day'].unique()
Out[36]:
['Sun', 'Sat', 'Thur', 'Fri'] Categories (4, object): ['Thur', 'Fri', 'Sat', 'Sun']
In [38]:
# 요일 별로 그룹화해서 몇 명이 왔는지 카운트
tips.groupby("day").count()
Out[38]:
total_bill | tip | sex | smoker | time | size | |
---|---|---|---|---|---|---|
day | ||||||
Thur | 62 | 62 | 62 | 62 | 62 | 62 |
Fri | 19 | 19 | 19 | 19 | 19 | 19 |
Sat | 87 | 87 | 87 | 87 | 87 | 87 |
Sun | 76 | 76 | 76 | 76 | 76 | 76 |
In [39]:
group = tips.groupby("day").count()['total_bill']
# list 형으로 형변환
x = list(group.index)
y = list(group) # 갯수만 얻어옴
# 요일별 방문 사람 수 시각화
plt.bar(x, y)
Out[39]:
<BarContainer object of 4 artists>
In [67]:
# 요일 별 총 금액 확인
group = tips.groupby("day")['total_bill'].sum()
# list 형으로 형변환
x = list(group.index)
y = list(group) # 갯수만 얻어옴
# 요일별 금액 확인
plt.bar(x, y)
Out[67]:
<BarContainer object of 4 artists>
In [68]:
# 요일 별 총 금액 확인
group = tips.groupby("day")['total_bill'].sum()
# list 형으로 형변환
x = list(group.index)
y = list(group) # 갯수만 얻어옴
# 요일별 금액 확인
sns.barplot(x=x, y=y)
Out[68]:
<Axes: >
In [43]:
tips.groupby('day').describe()
Out[43]:
total_bill | tip | size | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | mean | std | min | 25% | 50% | 75% | max | count | mean | ... | 75% | max | count | mean | std | min | 25% | 50% | 75% | max | |
day | |||||||||||||||||||||
Thur | 62.0 | 17.682742 | 7.886170 | 7.51 | 12.4425 | 16.20 | 20.1550 | 43.11 | 62.0 | 2.771452 | ... | 3.3625 | 6.70 | 62.0 | 2.451613 | 1.066285 | 1.0 | 2.0 | 2.0 | 2.0 | 6.0 |
Fri | 19.0 | 17.151579 | 8.302660 | 5.75 | 12.0950 | 15.38 | 21.7500 | 40.17 | 19.0 | 2.734737 | ... | 3.3650 | 4.73 | 19.0 | 2.105263 | 0.567131 | 1.0 | 2.0 | 2.0 | 2.0 | 4.0 |
Sat | 87.0 | 20.441379 | 9.480419 | 3.07 | 13.9050 | 18.24 | 24.7400 | 50.81 | 87.0 | 2.993103 | ... | 3.3700 | 10.00 | 87.0 | 2.517241 | 0.819275 | 1.0 | 2.0 | 2.0 | 3.0 | 5.0 |
Sun | 76.0 | 21.410000 | 8.832122 | 7.25 | 14.9875 | 19.63 | 25.5975 | 48.17 | 76.0 | 3.255132 | ... | 4.0000 | 6.50 | 76.0 | 2.842105 | 1.007341 | 2.0 | 2.0 | 2.0 | 4.0 | 6.0 |
4 rows × 24 columns
In [49]:
fig, axes = plt.subplots(1, 2, figsize=(10,3))
# palette : 색상 설정
# ci : 분포 삭제
sns.barplot(x="day", y="total_bill", data=tips, palette="deep", ax=axes[1], ci=None)
Out[49]:
<Axes: xlabel='day', ylabel='total_bill'>
In [ ]:
In [ ]:
Seaborn 그래프( https://seaborn.pydata.org/tutorial/function_overview.html )¶
그래프를 그리고자 할때는 속성값이 수치형인지, 카테고리형(범주형)인지를 파악 후 선택하는 것이 좋다
수치형
- relplot : 관계를 나타내고자 할때 사용한다
- scatterplot : 산포도(x,y를 점으로 표현)
- lineplot : 선 그래프
- displot : 분포를 나타내고자 할때 사용한다
- relplot : 관계를 나타내고자 할때 사용한다
카테고리형(범주형) 남자, 여자 등 분류가 정해져 있는 데이터
- catplot : 카테고리형(범주형)을 표현할때 사용하며, 남자, 여자 등 분류가 정해져 있는 데이터 이용할 때 사용한다
In [50]:
tips.head()
Out[50]:
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
In [52]:
# 판매량 당 팁 발생 확인
sns.relplot(x = "total_bill", y = "tip", data = tips)
Out[52]:
<seaborn.axisgrid.FacetGrid at 0x193b2af9ed0>
In [54]:
# hue 를 사용해서 요일 별로 그룹화하여 시각화해줌
sns.relplot(x = "total_bill", y = "tip", hue="day", data = tips)
Out[54]:
<seaborn.axisgrid.FacetGrid at 0x193b905c250>
In [55]:
# 날짜 별로 그래프를 분리
sns.relplot(x = "total_bill", y = "tip", hue="day", data = tips, col="day")
Out[55]:
<seaborn.axisgrid.FacetGrid at 0x193b9091710>
In [58]:
# scatterplot 을 사용해서도 요일 별로 그래프를 분류할 수 있다
sns.scatterplot(x = "total_bill", y = "tip", hue="day", data = tips)
Out[58]:
<Axes: xlabel='total_bill', ylabel='tip'>
In [62]:
# scatterplot 의 타이틀 지정 ( 변수로 그래프를 저장하여 타이틀 지정해야 함 )
g = sns.scatterplot(x = "total_bill", y = "tip", hue="day", data = tips)
g.set_title("scatter test", fontsize=20, color="blue")
Out[62]:
Text(0.5, 1.0, 'scatter test')
In [63]:
# lineplot 을 사용하여 선으로 그래프를 표현
g = sns.lineplot(x = "total_bill", y = "tip", hue="day", data = tips)
In [70]:
# titanic 에 대한 dataset 도 seaborn 에서 기본 제공
t = sns.load_dataset("titanic")
t.head()
Out[70]:
survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
In [74]:
# 연령별 탑승 수 확인
# color 를 skyblue 로 변환
sns.histplot(x="age", data=t, bins=10, color="skyblue")
Out[74]:
<Axes: xlabel='age', ylabel='Count'>
In [80]:
# sns.barplot(x="sex", y="tip", data=tips)
r = sns.barplot(x=tips["sex"], y=tips["tip"])
r.set_xlabel("성별", fontsize=10)
r.set_ylabel("팁", fontsize=10)
r.set_title("bar")
Out[80]:
Text(0.5, 1.0, 'bar')
In [84]:
sns.boxplot(x="day", y="tip", data=tips)
Out[84]:
<Axes: xlabel='day', ylabel='tip'>
In [86]:
# 담배를 피는 사람과 피지 않는 사람의 팁 차이 를 요일별로 확인
sns.boxplot(x="day", y="tip", hue="smoker", data=tips)
Out[86]:
<Axes: xlabel='day', ylabel='tip'>
In [92]:
# 각 컬럼의 상관관계를 확인
# tip 이 올라갈때 total_bill 이 올라가면
# 수치가 1과 가깝게 나옴
tips.corr(numeric_only=True)
Out[92]:
total_bill | tip | size | |
---|---|---|---|
total_bill | 1.000000 | 0.675734 | 0.598315 |
tip | 0.675734 | 1.000000 | 0.489299 |
size | 0.598315 | 0.489299 | 1.000000 |
In [98]:
# 각 컬럼의 상관관계를 시각화 ( heatmap 사용 )
# annot = True : 수치를 숫자로 나타내준다
# 수치가 0.7 이상이면 서로 깊은 연관관계가 있다
sns.heatmap(tips.corr(numeric_only=True), annot=True)
Out[98]:
<Axes: >
In [99]:
!pip list
Package Version --------------------------------- ------------ aiobotocore 2.7.0 aiohttp 3.9.3 aioitertools 0.7.1 aiosignal 1.2.0 alabaster 0.7.12 altair 5.0.1 anaconda-anon-usage 0.4.3 anaconda-catalogs 0.2.0 anaconda-client 1.12.3 anaconda-cloud-auth 0.1.4 anaconda-navigator 2.5.2 anaconda-project 0.11.1 anyio 4.2.0 appdirs 1.4.4 archspec 0.2.1 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 arrow 1.2.3 astroid 2.14.2 astropy 5.3.4 asttokens 2.0.5 async-lru 2.0.4 atomicwrites 1.4.0 attrs 23.1.0 Automat 20.2.0 autopep8 1.6.0 Babel 2.11.0 backports.functools-lru-cache 1.6.4 backports.tempfile 1.0 backports.weakref 1.0.post1 bcrypt 3.2.0 beautifulsoup4 4.12.2 binaryornot 0.4.4 black 23.11.0 bleach 4.1.0 blinker 1.6.2 bokeh 3.3.4 boltons 23.0.0 botocore 1.31.64 Bottleneck 1.3.7 Brotli 1.0.9 cachetools 4.2.2 certifi 2024.2.2 cffi 1.16.0 chardet 4.0.0 charset-normalizer 2.0.4 click 8.1.7 cloudpickle 2.2.1 clyent 1.2.2 colorama 0.4.6 colorcet 3.0.1 comm 0.1.2 conda 24.1.2 conda-build 24.1.2 conda-content-trust 0.2.0 conda_index 0.4.0 conda-libmamba-solver 24.1.0 conda-pack 0.6.0 conda-package-handling 2.2.0 conda_package_streaming 0.9.0 conda-repo-cli 1.0.75 conda-token 0.4.0 conda-verify 3.4.2 constantly 23.10.4 contourpy 1.2.0 cookiecutter 2.5.0 cryptography 42.0.2 cssselect 1.2.0 cycler 0.11.0 cytoolz 0.12.2 dask 2023.11.0 datashader 0.16.0 debugpy 1.6.7 decorator 5.1.1 defusedxml 0.7.1 diff-match-patch 20200713 dill 0.3.7 distributed 2023.11.0 distro 1.8.0 docstring-to-markdown 0.11 docutils 0.18.1 entrypoints 0.4 et-xmlfile 1.1.0 executing 0.8.3 fastjsonschema 2.16.2 filelock 3.13.1 flake8 6.0.0 Flask 2.2.5 fonttools 4.25.0 frozenlist 1.4.0 fsspec 2023.10.0 future 0.18.3 gensim 4.3.0 gitdb 4.0.7 GitPython 3.1.37 gmpy2 2.1.2 greenlet 3.0.1 h5py 3.9.0 HeapDict 1.0.1 holoviews 1.18.3 hvplot 0.9.2 hyperlink 21.0.0 idna 3.4 imagecodecs 2023.1.23 imageio 2.33.1 imagesize 1.4.1 imbalanced-learn 0.11.0 importlib-metadata 7.0.1 incremental 22.10.0 inflection 0.5.1 iniconfig 1.1.1 intake 0.6.8 intervaltree 3.1.0 ipykernel 6.28.0 ipython 8.20.0 ipython-genutils 0.2.0 ipywidgets 7.6.5 isort 5.9.3 itemadapter 0.3.0 itemloaders 1.1.0 itsdangerous 2.0.1 jaraco.classes 3.2.1 jedi 0.18.1 jellyfish 1.0.1 Jinja2 3.1.3 jmespath 1.0.1 joblib 1.2.0 json5 0.9.6 jsonpatch 1.32 jsonpointer 2.1 jsonschema 4.19.2 jsonschema-specifications 2023.7.1 jupyter 1.0.0 jupyter_client 8.6.0 jupyter-console 6.6.3 jupyter_core 5.5.0 jupyter-events 0.8.0 jupyter-lsp 2.2.0 jupyter_server 2.10.0 jupyter_server_terminals 0.4.4 jupyterlab 4.0.11 jupyterlab-pygments 0.1.2 jupyterlab_server 2.25.1 jupyterlab-widgets 3.0.9 keyring 23.13.1 kiwisolver 1.4.4 lazy_loader 0.3 lazy-object-proxy 1.6.0 lckr_jupyterlab_variableinspector 3.1.0 libarchive-c 2.9 libmambapy 1.5.6 linkify-it-py 2.0.0 llvmlite 0.42.0 lmdb 1.4.1 locket 1.0.0 lxml 4.9.3 lz4 4.3.2 Markdown 3.4.1 markdown-it-py 2.2.0 MarkupSafe 2.1.3 matplotlib 3.8.0 matplotlib-inline 0.1.6 mccabe 0.7.0 mdit-py-plugins 0.3.0 mdurl 0.1.0 menuinst 2.0.2 mistune 2.0.4 mkl-fft 1.3.8 mkl-random 1.2.4 mkl-service 2.4.0 more-itertools 10.1.0 mpmath 1.3.0 msgpack 1.0.3 multidict 6.0.4 multipledispatch 0.6.0 munkres 1.1.4 mypy 1.8.0 mypy-extensions 1.0.0 navigator-updater 0.4.0 nbclient 0.8.0 nbconvert 7.10.0 nbformat 5.9.2 nest-asyncio 1.6.0 networkx 3.1 nltk 3.8.1 notebook 7.0.8 notebook_shim 0.2.3 numba 0.59.0 numexpr 2.8.7 numpy 1.26.4 numpydoc 1.5.0 openpyxl 3.0.10 overrides 7.4.0 packaging 23.1 pandas 2.1.4 pandocfilters 1.5.0 panel 1.3.8 param 2.0.2 paramiko 2.8.1 parsel 1.8.1 parso 0.8.3 partd 1.4.1 pathlib 1.0.1 pathspec 0.10.3 patsy 0.5.3 pexpect 4.8.0 pickleshare 0.7.5 pillow 10.2.0 pip 23.3.1 pkce 1.0.3 pkginfo 1.9.6 platformdirs 3.10.0 plotly 5.9.0 pluggy 1.0.0 ply 3.11 prometheus-client 0.14.1 prompt-toolkit 3.0.43 Protego 0.1.16 protobuf 3.20.3 psutil 5.9.0 ptyprocess 0.7.0 pure-eval 0.2.2 py-cpuinfo 9.0.0 pyarrow 14.0.2 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycodestyle 2.10.0 pycosat 0.6.6 pycparser 2.21 pyct 0.5.0 pycurl 7.45.2 pydantic 1.10.12 pydeck 0.8.0 PyDispatcher 2.0.5 pydocstyle 6.3.0 pyerfa 2.0.0 pyflakes 3.0.1 Pygments 2.15.1 PyJWT 2.4.0 pylint 2.16.2 pylint-venv 2.3.0 pyls-spyder 0.4.0 PyNaCl 1.5.0 pyodbc 5.0.1 pyOpenSSL 24.0.0 pyparsing 3.0.9 PyQt5 5.15.10 PyQt5-sip 12.13.0 PyQtWebEngine 5.15.6 PySocks 1.7.1 pytest 7.4.0 python-dateutil 2.8.2 python-dotenv 0.21.0 python-json-logger 2.0.7 python-lsp-black 1.2.1 python-lsp-jsonrpc 1.0.0 python-lsp-server 1.7.2 python-slugify 5.0.2 python-snappy 0.6.1 pytoolconfig 1.2.6 pytz 2023.3.post1 pyviz_comms 3.0.0 pywavelets 1.5.0 pywin32 305.1 pywin32-ctypes 0.2.0 pywinpty 2.0.10 PyYAML 6.0.1 pyzmq 25.1.2 QDarkStyle 3.0.2 qstylizer 0.2.2 QtAwesome 1.2.2 qtconsole 5.4.2 QtPy 2.4.1 queuelib 1.6.2 referencing 0.30.2 regex 2023.10.3 requests 2.31.0 requests-file 1.5.1 requests-toolbelt 1.0.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.3.5 rope 1.7.0 rpds-py 0.10.6 Rtree 1.0.1 ruamel.yaml 0.17.21 ruamel-yaml-conda 0.17.21 s3fs 2023.10.0 scikit-image 0.22.0 scikit-learn 1.2.2 scipy 1.11.4 Scrapy 2.8.0 seaborn 0.12.2 semver 2.13.0 Send2Trash 1.8.2 service-identity 18.1.0 setuptools 68.2.2 sip 6.7.12 six 1.16.0 smart-open 5.2.1 smmap 4.0.0 sniffio 1.3.0 snowballstemmer 2.2.0 sortedcontainers 2.4.0 soupsieve 2.5 Sphinx 5.0.2 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 spyder 5.4.3 spyder-kernels 2.4.4 SQLAlchemy 2.0.25 stack-data 0.2.0 statsmodels 0.14.0 streamlit 1.30.0 sympy 1.12 tables 3.9.2 tabulate 0.9.0 tblib 1.7.0 tenacity 8.2.2 terminado 0.17.1 text-unidecode 1.3 textdistance 4.2.1 threadpoolctl 3.1.0 three-merge 0.1.1 tifffile 2023.4.12 tinycss2 1.2.1 tldextract 3.2.0 toml 0.10.2 tomlkit 0.11.1 toolz 0.12.0 tornado 6.3.3 tqdm 4.65.0 traitlets 5.7.1 truststore 0.8.0 Twisted 23.10.0 twisted-iocpsupport 1.0.2 typing_extensions 4.9.0 tzdata 2023.3 tzlocal 2.1 uc-micro-py 1.0.1 ujson 5.4.0 Unidecode 1.2.0 urllib3 2.0.7 validators 0.18.2 w3lib 2.1.2 watchdog 2.1.6 wcwidth 0.2.5 webencodings 0.5.1 websocket-client 0.58.0 Werkzeug 2.2.3 whatthepatch 1.0.2 wheel 0.41.2 widgetsnbextension 3.5.2 win-inet-pton 1.1.0 wrapt 1.14.1 xarray 2023.6.0 xlwings 0.29.1 xyzservices 2022.9.0 yapf 0.31.0 yarl 1.9.3 yellowbrick 1.5 zict 3.0.0 zipp 3.17.0 zope.interface 5.4.0 zstandard 0.19.0
In [100]:
pip install seaborn --upgrade
Requirement already satisfied: seaborn in c:\users\user\anaconda3\lib\site-packages (0.12.2) Collecting seaborn Downloading seaborn-0.13.2-py3-none-any.whl.metadata (5.4 kB) Requirement already satisfied: numpy!=1.24.0,>=1.20 in c:\users\user\anaconda3\lib\site-packages (from seaborn) (1.26.4) Requirement already satisfied: pandas>=1.2 in c:\users\user\anaconda3\lib\site-packages (from seaborn) (2.1.4) Requirement already satisfied: matplotlib!=3.6.1,>=3.4 in c:\users\user\anaconda3\lib\site-packages (from seaborn) (3.8.0) Requirement already satisfied: contourpy>=1.0.1 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.2.0) Requirement already satisfied: cycler>=0.10 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (0.11.0) Requirement already satisfied: fonttools>=4.22.0 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (4.25.0) Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (1.4.4) Requirement already satisfied: packaging>=20.0 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (23.1) Requirement already satisfied: pillow>=6.2.0 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (10.2.0) Requirement already satisfied: pyparsing>=2.3.1 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (3.0.9) Requirement already satisfied: python-dateutil>=2.7 in c:\users\user\anaconda3\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (2.8.2) Requirement already satisfied: pytz>=2020.1 in c:\users\user\anaconda3\lib\site-packages (from pandas>=1.2->seaborn) (2023.3.post1) Requirement already satisfied: tzdata>=2022.1 in c:\users\user\anaconda3\lib\site-packages (from pandas>=1.2->seaborn) (2023.3) Requirement already satisfied: six>=1.5 in c:\users\user\anaconda3\lib\site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.4->seaborn) (1.16.0) Downloading seaborn-0.13.2-py3-none-any.whl (294 kB) ---------------------------------------- 0.0/294.9 kB ? eta -:--:-- - -------------------------------------- 10.2/294.9 kB ? eta -:--:-- --------- ----------------------------- 71.7/294.9 kB 991.0 kB/s eta 0:00:01 ---------------------------------------- 294.9/294.9 kB 3.1 MB/s eta 0:00:00 Installing collected packages: seaborn Attempting uninstall: seaborn Found existing installation: seaborn 0.12.2 Uninstalling seaborn-0.12.2: Successfully uninstalled seaborn-0.12.2 Successfully installed seaborn-0.13.2 Note: you may need to restart the kernel to use updated packages.
In [8]:
# 각 컬럼의 상관관계를 시각화 ( heatmap 사용 )
# annot = True : 수치를 숫자로 나타내준다
# 수치가 0.7 이상이면 서로 깊은 연관관계가 있다
sns.heatmap(tips.corr(numeric_only=True), annot=True)
# seaborn 으로 heatmap 그리는데 annot=True 를 설정해도
# 맨 윗줄 한 줄만 숫자가 나타남
# seaborn 버전 0.12.2 에서 자주 발생하는 문제라 함
# 버전을 0.13.2 로 올린 뒤 우측 상단의 Python 3 (ipykernel) 부분
# 클릭해서 커널 다시 재실행 후 시작하니 정상 작동
Out[8]:
<Axes: >
728x90
'BE > 머신러닝(ML)' 카테고리의 다른 글
[머신러닝] 지도학습 ( 분류, 회귀 ), 평가지표 선택하는 방법 (0) | 2024.05.24 |
---|---|
[머신러닝] 탐색적 데이터분석 ( EDA, 표준화, 가중치 ) (0) | 2024.05.24 |
[머신러닝] 실습 예제 및 풀이 (1) | 2024.05.23 |
[머신러닝] 데이터 전처리 ( 그룹 ) (0) | 2024.05.23 |
[머신러닝] 데이터 전처리 ( 시계열 ) (0) | 2024.05.23 |