๋ฐ์ดํฐ์ ๋ถ๋ฌ์ค๊ธฐ
import pandas as pd
pd.read_csv('')
๋ฐ์ดํฐ์ ๊ฐ๋จํ๊ฒ ํ์ธ
์ฒซ๋ฒ์งธ๋ถํฐ ๋ค์ฏ๋ฒ์งธ row ํ์ธ(์ค์ ๋ฐ์ดํฐ๋ฅผ ๋๋ต ์ฒดํฌํ ๋ ์์ฃผ ์์ฃผ ์ฌ์ฉ๋จ) ๊ฑ ์๋๋๋ ์์ด ์ฌ์ฉ๋จ
df.head()
๋ฐ์ดํฐ์ ๋ชจ์ ํ์ธ(df์ ํ๊ณผ ์ด ๊ฐฏ์, ๊ตฌ์กฐ๋ฅผ ๊ฐ๋จํ๊ฒ ํํ ๋ณด์ฌ์ค)
df.shape
EDA(Exploratory Data Analysis) ์์ฃผ ์ค์ํ ๊ฐ๋ ์ฐ
์ฐ๋ฆฌ๊ฐ ์ง์ธ์ผ๋ก๋ถํฐ ์์ ์ ๋ฌผ์ ๋ฐ์๋ค. ์ด์ ์ด๊ฑธ ์ด๋ป๊ฒ ํ ๊น. ์ช๋จน์๊น ํํด๋จน์๊น ์๋๋ฉด ํ์ด์ค๊น ๋ญ ์ด๋ป๊ฒ ํ ๊น
- ์์ ์ ๋ ์ ์์๊น
- ๋จน์ ์ ์๋ ๋ถ๋ถ์ ์๋
- ์์ ์ด ๋ง๊ธด ํด?
- ์๋ฆฌํ๊ธฐ ์ํ ์ฌ๋ฌ ๊ฐ์ ex)์ ์ ํ๋ฉด ํ๋ ๊ฐ๋ฅํ๋ค!
์ ๊ฐ์ด ๋ฐ์ดํฐ๋ ์ด๋ฆฌ์ ๋ฆฌ ๊ฒฐ์ธก์น๋ ์๋์ง, ๋ญ ๋ฐ์ดํฐ ํฌ๊ธฐ๋ ์ด๋ค์ง, ์นผ๋ผ๋ณ๋ก ๋ฌด์จ ์๋ฃํ์ธ์ง ๋ฑ๋ฑ ์ ์ ํ ํ์ ํ๋ ๊ฒ
์ด๊ฒ ํ์์ ๋ฐ์ดํฐ ๋ถ์! ์ฐ๋ฆฌ๊ฐ ์ฒ์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ผ๋ฉด ์ด ๋ฐ์ดํฐ์ ๋ํ ๊ฒฌ์ ์ ๋ด์ผํ๋ค. ์ด๊ฒ ๊ณง EDA์ด๋ค.
Graphic ๋ฐฉ๋ฒ
- ์ฐจํธ ํน์ ๊ทธ๋ฆผ ๋ฑ์ ์ด์ฉํ์ฌ(์๊ฐํ๋ฅผ ํตํ์ฌ) ๋ฐ์ดํฐ๋ฅผ ํ์ธํ๋ ๋ฐฉ๋ฒ
Non-Graphic ๋ฐฉ๋ฒ
- ์๊ฐ์ ์ธ ์์๊ฐ ์๋ ์ฃผ๋ก Summary Statistics๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ํ์ธํ๋ ๋ฐฉ๋ฒ
df.describe()
๋์์ EDA์ ํ๊ฒ ๋ฐ์ดํฐ์ ๋ฐ๋ผ Univaraite, Multi-variate 2๊ฐ์ง๋ก ๋๋์ด์ง๋ค.
์ฆ, ์กฐํฉ์ด 2x2๋ก 4๊ฐ์ง
Uni-Graphic
Histogram, Pie chart, Boxplot, QQplot ๋ฑ์ด ์๋ค.
QQplot : ๋ฐ์ดํฐ์ ๋ถํฌ์ ์ด๋ก ์ ๋ถํฌ๊ฐ ์ ์ผ์นํ๋๊ฐ๋ฅผ ํ์ธํ ์ ์๋ ๋ฐฉ๋ฒ
ex) ์ฑ์ ๋ถํฌ๊ฐ ์ด๋๊ฐ ๋ ๊ณ ๋ฅธ๊ฐ
A๋ฐ : 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
B๋ฐ : 10, 15, 20, 75, 80, 85, 90, 95, 95, 100
์ด์ธ์ ๋ค๋ฅธ QQplot
Uni-NonGraphic
Sample Data์ Distribution์ ํ์ธํ๋ ๊ฒ์ด ์ฃผ๋ชฉ์
Numeric data์ ๊ฒฝ์ฐ summary statistics๋ฅผ ์ ์ผ ๋ง์ด ํ์ฉํ๋๋ฐ, ์ฌ๊ธฐ์๋
Center (Mean, Median, Mod)
Spread (Variance, SD, IQR, Range)
Modality (Peak)
Shape (Tail, Skewness, Kurtosis)
Outliers
๋ฑ์ด ์๋ค.
Multi-Graphic
- Category&Numeric : Boxplots, Stacked bar, Parallel Coordinate, Heatmap ๋ฑ
- Numeric&Numeric : Scatter Plot
pandas๋ฅผ ์ฌ์ฉํ ๊ธฐ์ด EDA
์ ์ฉํ ์ ๋ค(์์ฃผ ์ฐ๋ ์ ๋ค)
Missing Data(๊ฒฐ์ธก์น)
- isna
- dropna
- fillna
Data Frame(๋ฐ์ดํฐ ๊ตฌ์กฐ ํ์ )
- index
- columns
- dtypes
- info
- loc
- iloc
- head
- replace
- describe
- shape
Visible(์๊ฐํํ ๋)
- plot
- plot.bar
- plot.hist
- plot.box
- plot.pie
- plot.scatter
์๊ฐํ์ <matplotlib.~> ์์ ๋ ๋ฒ
๋์ ; ๋ฅผ ๋ถ์ฌ์ค๋ค.
ํ๊ธ ํฐํธ ๋์ค๊ฒ ํ๋ ๋ฒ
๋จผ์ ํ๊ธ ํฐํธ๋ฅผ ๋ฐ๊ณ
!sudo apt-get install -y fonts-nanum
!sudo fc-cache -fv
!rm ~\.cache\matplotlib -rf
๊ธ๊ผด์ ์ค์ ํด์ค๋ค.
import matplotlib.pyplot as plt
plt.rc('font', family='NanumBarunGothic')
Data Preprocessing
- ์์ข์ ๋ฐ์ดํฐ๊ฐ ๋ค์ด๊ฐ๋ฉด ์๋ฌด๋ฆฌ ๋ชจ๋ธ์ด ์ข์๋ ์์ข์ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค.
๋ฐ์ดํฐ ํน์ ๋ถ์, ์์ ๋ง๋ค ํด์ผํ๋ ๋ฐ์ดํฐ์ ์ ์ฒ๋ฆฌ๋ ๋ค๋ฅด์ง๋ง ํฌ๊ฒ ์๋์ ๊ฐ์ ํ๋ฆ์ ๊ฐ๋๋ค.
Cleaning
- noise๋ฅผ ์ ๊ฑฐํ๊ฑฐ๋, inconsistency๋ฅผ ๋ณด์ ํ๋ ๊ณผ์ ์ ์๋ฏธ
Missing Values ์ฒ๋ฆฌ ๋ฐฉ๋ฒ
- ๊ทธ๋ฅ ์ญ์
- ์๋์ผ๋ก ์ ๋ ฅ
- global constant(๊ทธ๋ฅ ๊ฐ์ ์ ํด์ ๋ฃ๋ ๊ฒ)
- Imputation(ํ๊ท , ์ค์๊ฐ, ํ๊ท๋ฅผ ํตํ ๊ฐ์ ๋ฃ์)
Noisy data
ํฐ ๋ฐฉํฅ์ฑ์์ ๋ฒ์ด๋ random error ํน์ variance ๋ฑ์ ํฌํจํ๋ ๋ฐ์ดํฐ
๋๋ถ๋ถ descriptive statistics ํน์ visualization ๋ฑ์ eda๋ฅผ ํตํด ์ ๊ฑฐ ๊ฐ๋ฅ
Integration
์ฌ๋ฌ ๊ฐ๋ก ๋๋์ด์ง ๋ฐ์ดํฐ๋ค์ ๋ถ์ํ๊ธฐ ํธํ๊ฒ ํ๋๋ก ํฉ์น๋ ๊ณผ์
ex) merge
Transformation
๋ฐ์ดํฐ์ ํํ๋ฅผ ๋ณํํ๋ ์์
์ผ๋ก, scaling์ด๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํฉ๋๋ค.
ex) normalize
Reduction
๋ฐ์ดํฐ๋ฅผ ์๋ฏธ์๊ฒ ์ค์ด๋ ๊ฒ์ ์๋ฏธํ๋ฉฐ, dimension reduction๊ณผ ์ ์ฌํ ๋ชฉ์ ์ ๊ฐ๋๋ค.
ex) PCA
'๐ฟ Data > ๋ถํธ์บ ํ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TIL]8.Confidence Intervals (0) | 2021.11.27 |
---|---|
[TIL]7.Hypothesis Test + (0) | 2021.11.26 |
[TIL]6.Hypothesis Test (0) | 2021.11.24 |
[TIL]5.์ฝ๋์คํ ์ด์ธ AI ์คํ๋ฆฐํธ ์ฑ๋ฆฐ์ง (0) | 2021.11.24 |
00. ๋ถํธ์บ ํ์ ๋ค์ด๊ฐ๊ธฐ์ ์์ (2) | 2021.11.15 |