16 Wed
TIL
ํ๋ก๊ทธ๋๋จธ์ค AI ์ค์ฟจ 1๊ธฐ
3์ฃผ์ฐจ DAY 3
Matlab์ผ๋ก ๋ฐ์ดํฐ ์๊ฐํํ๊ธฐ
๋ฐ์ดํฐ๋ฅผ ๋ณด๊ธฐ์ข๊ฒ ํํํด๋ด ์๋ค.
1. Matplotlib ์์ํ๊ธฐ
2. ์์ฃผ ์ฌ์ฉ๋๋ Plotting์ Options
ํฌ๊ธฐ :
figsize
์ ๋ชฉ :
title
๋ผ๋ฒจ :
_label
๋๊ธ :
_tics
๋ฒ๋ก :
legend
3. Matplotlib Case Study
๊บพ์์ ๊ทธ๋ํ (Plot)
์ฐ์ ๋ (Scatter Plot)
๋ฐ์ค๊ทธ๋ฆผ (Box Plot)
๋ง๋๊ทธ๋ํ (Bar Chart)
์ํ๊ทธ๋ํ (Pie Chart)
4. The ๋ฉ์ง ๊ทธ๋ํ, seaborn Case Study
์ปค๋๋ฐ๋๊ทธ๋ฆผ (Kernel Density Plot)
์นด์ดํธ๊ทธ๋ฆผ (Count Plot)
์บฃ๊ทธ๋ฆผ (Cat Plot)
์คํธ๋ฆฝ๊ทธ๋ฆผ (Strip Plot)
ํํธ๋งต (Heatmap)
I. Matplotlib ์์ํ๊ธฐ
ํ์ด์ฌ์ ๋ฐ์ดํฐ ์๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
cf) ๋ผ์ด๋ธ๋ฌ๋ฆฌ vs ํ๋ ์์ํฌ
๋ผ์ด๋ธ๋ฌ๋ฆฌ : ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ด๋ถ ์ฝ๋๋ฅผ ์กฐํฉํด์ ๊ฒฐ๊ณผ๋ฅผ ๋์ถ
ex : numpy, pandas
ํ๋ ์์ํฌ : ์ ํด์ ธ ์๋ ํ์ ๋ด์ฉ๋ฌผ์ ์ฑ์๊ฐ
ex : django, flask
pip install matplotlib
%matplotlib inline
: ํ์ฑํ
II. Matplotlib Case Study
Figsize : Figure(๋๋ฉด)์ ํฌ๊ธฐ ์กฐ์
figure : ๊ทธ๋ํ๋ฅผ ์ด๋ฃจ๋ ๋๋ฉด figsize๋ ํํ์ ์ด๋ฃจ๋ฉฐ 1๋น 72ํฝ์ ์ ์๋ฏธํ๋ค
2์ฐจํจ์ ๊ทธ๋ํ with plot()
III. Matplotlib Case Study
๊บพ์์ ๊ทธ๋ํ(Plot)
.plot()
์ฐ์ ๋ (Scatter Plot)
.scatter()
Plot : ๊ท์น์ฑ Scatter Plot : ์๊ด๊ด๊ณ
๋ฐ์ค ๊ทธ๋ฆผ (Box Plot)
์์นํ ๋ฐ์ดํฐ์ ๋ํ ์ ๋ณด (Q1, Q2, Q3, min, max)
๋ง๋ ๊ทธ๋ํ (Bar Plot)
๋ฒ์ฃผํ ๋ฐ์ดํฐ์ "๊ฐ"๊ณผ ๊ทธ ๊ฐ์ ํฌ๊ธฐ๋ฅผ ์ง์ฌ๊ฐํ์ผ๋ก ๋ํ๋ธ ๊ทธ๋ฆผ
.bar()
์ํ ๊ทธ๋ํ (Pie Chart)
๋ฐ์ดํฐ์์ ์ ์ฒด์ ๋ํ ๋ถ๋ถ์ ๋น์จ์ ๋ถ์ฑ๊ผด๋ก ๋ํ๋ธ ๊ทธ๋ํ
๋ค๋ฅธ ๊ทธ๋ํ์ ๋นํด์ ๋น์จ ํ์ธ์ ์ฉ์ด
.pie()
IV. The ๋ฉ์ง ๊ทธ๋ํ, Seaborn Case Study
Matplotlib๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ ๋ค์ํ ์๊ฐํ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ปค๋๋ฐ๋๊ทธ๋ฆผ
์นด์ดํธ๊ทธ๋ฆผ
์บฃ๊ทธ๋ฆผ
์คํธ๋ฆฝ๊ทธ๋ฆผ
ํํธ๋งต
Seaborn Import ํ๊ธฐ
์ปค๋๋ฐ๋๊ทธ๋ฆผ (Kernel Density Plot)
ํ์คํ ๊ทธ๋จ๊ณผ ๊ฐ์ ์ฐ์์ ์ธ ๋ถํฌ๋ฅผ ๊ณก์ ํํด์ ๊ทธ๋ฆฐ ๊ทธ๋ฆผ
sns.kdeplot()
์นด์ดํธ๊ทธ๋ฆผ (Count Plot)
๋ฒ์ฃผํ column์ ๋น๋์๋ฅผ ์๊ฐํ -> Groupby ํ์ ๋์๋ฅผ ํ๋ ๊ฒ๊ณผ ๋์ผํ ํจ๊ณผ
sns.countplot()
name
vote
0
Andy
True
1
Bob
True
2
Cat
False
name
vote
False
1
True
2
์บฃ๊ทธ๋ฆผ (Cat Plot)
concat์์ ๋ฐ์จ cat
์ซ์ํ ๋ณ์์ ํ๋ ์ด์์ ๋ฒ์ฃผํ ๊ด๊ณ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํจ์
sns.catplot()
Country/Region
Confirmed
Deaths
Recovered
Active
New cases
New deaths
New recovered
Deaths / 100 Cases
Recovered / 100 Cases
Deaths / 100 Recovered
Confirmed last week
1 week change
1 week % increase
WHO Region
0
Afghanistan
36263
1269
25198
9796
106
10
18
3.50
69.49
5.04
35526
737
2.07
Eastern Mediterranean
1
Albania
4880
144
2745
1991
117
6
63
2.95
56.25
5.25
4171
709
17.00
Europe
2
Algeria
27973
1163
18837
7973
616
8
749
4.16
67.34
6.17
23691
4282
18.07
Africa
3
Andorra
907
52
803
52
10
0
0
5.73
88.53
6.48
884
23
2.60
Europe
4
Angola
950
41
242
667
18
1
0
4.32
25.47
16.94
749
201
26.84
Africa
์คํธ๋ฆฝ๊ทธ๋ฆผ (Strip Plot)
scatter plot๊ณผ ์ ์ฌํ๊ฒ ๋ฐ์ดํฐ์ ์์น๋ฅผ ํํํ๋ ๊ทธ๋ํ
sns.stripplot()
ํํธ๋งต (Heatmap)
๋ฐ์ดํฐ์ ํ๋ ฌ์ ์์์ผ๋ก ํํํด์ฃผ๋ ๊ทธ๋ํ
sns.heatmap()
Confirmed
Deaths
Recovered
Active
New cases
New deaths
New recovered
Deaths / 100 Cases
Recovered / 100 Cases
Deaths / 100 Recovered
Confirmed last week
1 week change
1 week % increase
Confirmed
1.000000
0.934698
0.906377
0.927018
0.909720
0.871683
0.859252
0.063550
-0.064815
0.025175
0.999127
0.954710
-0.010161
Deaths
0.934698
1.000000
0.832098
0.871586
0.806975
0.814161
0.765114
0.251565
-0.114529
0.169006
0.939082
0.855330
-0.034708
Recovered
0.906377
0.832098
1.000000
0.682103
0.818942
0.820338
0.919203
0.048438
0.026610
-0.027277
0.899312
0.910013
-0.013697
Active
0.927018
0.871586
0.682103
1.000000
0.851190
0.781123
0.673887
0.054380
-0.132618
0.058386
0.931459
0.847642
-0.003752
New cases
0.909720
0.806975
0.818942
0.851190
1.000000
0.935947
0.914765
0.020104
-0.078666
-0.011637
0.896084
0.959993
0.030791
New deaths
0.871683
0.814161
0.820338
0.781123
0.935947
1.000000
0.889234
0.060399
-0.062792
-0.020750
0.862118
0.894915
0.025293
New recovered
0.859252
0.765114
0.919203
0.673887
0.914765
0.889234
1.000000
0.017090
-0.024293
-0.023340
0.839692
0.954321
0.032662
Deaths / 100 Cases
0.063550
0.251565
0.048438
0.054380
0.020104
0.060399
0.017090
1.000000
-0.168920
0.334594
0.069894
0.015095
-0.134534
Recovered / 100 Cases
-0.064815
-0.114529
0.026610
-0.132618
-0.078666
-0.062792
-0.024293
-0.168920
1.000000
-0.295381
-0.064600
-0.063013
-0.394254
Deaths / 100 Recovered
0.025175
0.169006
-0.027277
0.058386
-0.011637
-0.020750
-0.023340
0.334594
-0.295381
1.000000
0.030460
-0.013763
-0.049083
Confirmed last week
0.999127
0.939082
0.899312
0.931459
0.896084
0.862118
0.839692
0.069894
-0.064600
0.030460
1.000000
0.941448
-0.015247
1 week change
0.954710
0.855330
0.910013
0.847642
0.959993
0.894915
0.954321
0.015095
-0.063013
-0.013763
0.941448
1.000000
0.026594
1 week % increase
-0.010161
-0.034708
-0.013697
-0.003752
0.030791
0.025293
0.032662
-0.134534
-0.394254
-0.049083
-0.015247
0.026594
1.000000
Last updated
Was this helpful?