본문 바로가기
카테고리 없음

원-핫 인코딩(One Hot Encoding)

by 호놀롤롤 2024. 2. 19.
## 원 핫 인코딩
- 문자를 숫자로 변경하는 것, Label Encoding과의 차이점

from sklearn.preprocessing import OneHotEncoder
import numpy as np

items=['TV','냉장고','전자레인지','컴퓨터','선풍기','선풍기','믹서','믹서']


# 2차원 ndarray로 변환한다.
items = np.array(items).reshape(-1, 1)
print(items.shape)

 

 

 

 

oh_labels = oh_encoder.transform(items)
oh_labels.toarray()

 

 

 

 

 

 

df = pd.DataFrame({'item':['TV','냉장고','전자레인지','컴퓨터','선풍기','선풍기','믹서','믹서'] })
pd.get_dummies(df)