2019. 9. 10. 19:00ㆍ분석 Python/구현 및 자료
도움이 되셨다면, 광고 한번만 눌러주세요. 블로그 관리에 큰 힘이 됩니다 ^^
categorical 변수 가장 빈도수 많은 것으로 대체할 때,
df_most_common_imputed = colors.apply(lambda x: x.fillna(x.value_counts().index[0]))
df_most_common_imputed
## scikit-learn 0.2 버전
imputer=CategoricalImputer(strategy='most_frequent', axis=1)
imputer.fit(df[["col1", "col2"]])
imputer.transform(df)
(https://stackoverflow.com/questions/25239958/impute-categorical-missing-values-in-scikit-learn)
>> autoimpute
특징
1. Category 변수 가능
2. 변수별로 다르게 처리 가능
https://pypi.org/project/autoimpute/
autoimpute
Imputation Methods in Python
pypi.org

눈에 띄는 특징은 변수별로 처리를 다르게 할 수 있음
scikit learn과 호환돼서 할 수 있음
imp = MultipleImputer(
n=10,
strategy={"salary": "pmm", "gender": "bayesian binary logistic", "age": "norm"},
predictors={"salary": "all", "gender": ["salary", "education", "weight"]},
imp_kwgs={"pmm": {"fill_value": "random"}},
visit="left-to-right",
return_list=True
)
# Because we set return_list=True, imputations are done all at once, not evaluated lazily.
# This will return M*N, where M is the number of imputations and N is the size of original dataframe.
imp.fit_transform(data)
>> impyute
https://pypi.org/project/impyute/
impyute
Cross-sectional and time-series data imputation algorithms
pypi.org
mice , em , knn과 같은 일반적인 대체법들 많이 제공
categorical 변수에 대해서는 지원을 안 함.

>> Scikit-learn
https://scikit-learn.org/stable/modules/impute.html
5.4. Imputation of missing values — scikit-learn 0.21.3 documentation
5.4. Imputation of missing values For various reasons, many real world datasets contain missing values, often encoded as blanks, NaNs or other placeholders. Such datasets however are incompatible with scikit-learn estimators which assume that all values in
scikit-learn.org
>> datawig
https://github.com/awslabs/datawig
awslabs/datawig
Imputation of missing values in tables. Contribute to awslabs/datawig development by creating an account on GitHub.
github.com
장점
1. 딥러닝을 사용하고 categorial과 non-numerical features에서 잘 작동하는 방법.
2. CPU, GPU 둘 다 가능
3. 다른 방법들에 비해 정확함
단점
1. 변수 1개만 Imputation 가능
2. 큰 데이터셋에서는 느림
3. target columns에 대한 명시가 필요함.
>> missingpy
https://github.com/epsilon-machine/missingpy
epsilon-machine/missingpy
Missing Data Imputation for Python. Contribute to epsilon-machine/missingpy development by creating an account on GitHub.
github.com
k-Nearest Neighbors based imputation and Random Forest based imputation (MissForest)
numerical 변수만 가능함
수정) MissForest는 cat_var를 이용해서 카테고리 변수도 대체 가능 (대신 수치형으로 변환)
>> renom
추가 191103) mice 패키지에서 대체는거 있는거 존재함. (오래걸림)
Imputation 패키지는 아니지만 기능중에서 한개가 존재함
http://www.renom.jp/notebooks/tutorial/preprocessing/completion/notebook.html
http://www.renom.jp/notebooks/tutorial/preprocessing/completion/notebook.html
www.renom.jp
>> MIDA (multiple imputation using Denoising Autoencoders)
패키지는 아니지만, Denoising Autoencoder를 이용한 Multiple Imputation 방법
https://github.com/ambareeshsrja16/Python-Module-for-Missing-Data-Imputation
ambareeshsrja16/Python-Module-for-Missing-Data-Imputation
Implement an open source Python package for general purpose Missing Data Imputation using MIDA - ambareeshsrja16/Python-Module-for-Missing-Data-Imputation
github.com
https://arxiv.org/abs/1705.02737
특징
1. Denoising autoencoder 방식을 사용함.
2. Categorical 변수에 대해서도 작동함.
(https://github.com/Oracen/MIDAS/blob/master/midas/midas_base.py)
(추가 191110) knn_impute
Nuemrical , Category 둘 다 지원하고 distance를 사용하여서 변수를 Imputation함
https://gist.github.com/YohanObadia
YohanObadia’s gists
GitHub Gist: star and fork YohanObadia's gists by creating an account on GitHub.
gist.github.com
결론
기존에는 찾다보니 Numerical 한 변수에 대해서만 Imputation 하는 게 주로 보였지만,
점점 찾다보니, 패키지로는 안되어있어도, 본인들이 만들어 놓은 것들이 있는 것을 확인했다.
필요하면 만든다라는 사고 방식이 배워야겠다.
참고
6 Different Ways to Compensate for Missing Values In a Dataset (Data Imputation with examples)
Popular strategies to statistically impute missing values in a dataset.
towardsdatascience.com
https://jamesrledoux.com/code/imputation
Impute Missing Values
Impute Missing Values June 01, 2019 Real world data is filled with missing values. You will often need to rid your data of these missing values in order to train a model or do meaningful analysis. What follows are a few ways to impute (fill) missing values
jamesrledoux.com
'분석 Python > 구현 및 자료' 카테고리의 다른 글
[ Python ] 새로 만든 함수 수정 후 restart 안하고 reload하기 (0) | 2019.09.18 |
---|---|
[ Python ] custom logging level 만들기 (0) | 2019.09.11 |
[ Python ] How to fast String to pandas data frame 연습 (0) | 2019.09.04 |
[ Python ] logging 만들어보기 (FileHandler 와 StreamHandler 위주로) (0) | 2019.08.25 |
[ Python ] multiprocessing / concurrent.futures (0) | 2019.08.18 |