10.2 null 값 처리하기
- 결측치(Missing Data)
- 결측치가 있는 데이터를 제거한다.
- 결측치를 어떤 값으로 대체한다
- 특정값 지정 : .fillna()
- but, 결측치가 많은 경우, 모두 같은 값으로 대체한다면 데이터의 분산이 실제보다 작아지거나 편향되어 문제가 될 수 있음.
- 평균, 중앙값등으로 대체 : .fillna(df.mean())
- 1특정 값으로 대체했을 때와 마찬가지로 결측치가 많은 경우 데이터의 분산이 실제보다 작아지는 문제가 발생할 수 있음.
- 다른 데이터를 이용해 예측값으로 대체할 수 있습니다. 예를 들어 머신러닝 모델로 2020년 4월 미국의 예측값을 만들고, 이 값으로 결측치를 보완할 수 있습니다.
- 시계열 특성을 가진 데이터의 경우 앞뒤 데이터를 통해 결측치를 대체할 수 있습니다. 예를 들어 기온을 측정하는 센서 데이터에서 결측치가 발생할 경우, 전후 데이터의 평균으로 보완할 수 있습니다.
- 특정값 지정 : .fillna()
# .fillna()
fill_Dividend_df = sample_df.copy()
fill_Dividend_df['Dividend'] = sample_df['Dividend'].fillna(0)
fill_Dividend_df
# .fillna(df.mean())
fill_df = fill_Dividend_df.fillna(fill_Dividend_df.mean())
fill_df.iloc[222:225]
# groupby()응용
# x값을 lambda로 x의 mean값으로 채움
fill_Dividend_df.groupby('Category').mean()
fill_RoePer_df = fill_Dividend_df.groupby('Category').apply(lambda x: x.fillna(x.mean()))
fill_RoePer_df
https://brain-nim.tistory.com/20
10.4 첨부파일 참고
10.5.1 Standardization(Z-score), Normalization(MinMax Scaler)
- Standardization으로 이상치의 값을 추려내고,
- Normalization으로 값을 스케일링.
- Normalization != MinMax Scaler, Normalilzation 안에 하나의 방법으로 Min-Max Scaler가 들어가는 것.
- 번외) Regularization : 제약을 거는 것. (e.g. L1, L2, Regularization)
- z-score는 n이 10 이하이면 사용이 거의 불가함. 표본이 되기가 힘듬.
https://iq.opengenus.org/standardization-regularization-vs-normalization/
https://m.blog.naver.com/qbxlvnf11/221476122182
https://machinelearningmastery.com/standardscaler-and-minmaxscaler-transforms-in-python/
10.5.2 MinMax Scaler
train과 test 모두 minmax scaler를 동일하게 하지 않으면,
값의 편차가 너무 커서 정확한 예측이 힘듬.
10.5.3 그밖의 Scaler들
scaler 종류들
https://mingtory.tistory.com/140
sklearn MinMax Scaler 사용법
https://zephyrus1111.tistory.com/218
10.6. One-Hot Encoding
- How to Conver Categorical Data to Numerical Data
- Integer Encoding
- One-Hot Encoding
- Many machine learning algorithms cannot operate on label data directly. They require all input variables and output variables to be numeric.
- a decision tree can be learned directly from categorical data with no data transform required (this depends on the specific implementation)
https://machinelearningmastery.com/why-one-hot-encode-data-in-machine-learning/
(참고) 머신러닝 모델링의 흔한 실수들
728x90
'Study (Data Science) > ML' 카테고리의 다른 글
Batch size, Epoch, Iteration (0) | 2022.12.06 |
---|---|
여러가지 머신러닝 모델들 (0) | 2022.12.06 |
Day1. 데이터, 데이터베이스 (0) | 2022.12.04 |
EDA (Explratory Data Analysis) (1) | 2022.12.02 |
Matplotlib (0) | 2022.12.02 |
댓글