<jupyter_start><jupyter_text>OneHotEncoder()  `OneHotEncoder()`를 활용하여 범주형 자료를 더미화하는 방법 중 하나입니다. 서로 다른 데이터셋에서 적용할 때의 모습을 살펴보겠습니다. > 1. handle_unknown : 'ignore'> 2. handle_unknown : 'error' ***  데이터 만들기<jupyter_code>import pandas as pd
data = {'Wealth':[27, 32],
        'bld':['A',  'O']}

train = pd.DataFrame(data, index = ['Salah', 'Anuj'])
data = {'Wealth':[51,  22],
        'bld':['A', 'B']}

test = pd.DataFrame(data, index = ['Hwan', 'Jason'])
train
test<jupyter_output><empty_output><jupyter_text>***   OneHotEncoder(handle_unknown="ignore")<jupyter_code>from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder(handle_unknown="ignore", sparse = False)
encoder.fit(train[['bld']])
encoder.transform(train[['bld']])
encoder.transform(test[['bld']])<jupyter_output><empty_output><jupyter_text>새로운 값 B를 마주하자, 모든 벡터를 0으로 표기하였다. ***   OneHotEncoder(handle_unknown="error") > 원래 error가 default 값이기도 하다.<jupyter_code>from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder( sparse = False)
encoder.fit(train[['bld']])
encoder.transform(train[['bld']])
encoder.transform(test[['bld']])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17523975588491716, 'fraction_numerical': 0.00959023539668701, 'mean_word_length': 7.141843971631205, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '172644', 'license': 'MIT', 'n_tokens_mistral': 506, 'n_tokens_neox': 543, 'n_words': 83, 'path': '_posts/[Encoding] OHE/3. OneHotEncoding - handle_unknown.ipynb', 'repo_name': 'HaeHwan-Lee/HaeHwan-Lee.github.io', 'size': '1147'}