카테고리로 분류하고, sklearn의 LabelEncoder를 써주면 쉽네;
# #### 카테고리 변수를 수치로 변환하기
from sklearn.preprocessing import LabelEncoder
categories = all_df.columns[all_df.dtypes == "object"]
print(categories)
all_df["Alley"].value_counts()
for cat in categories:
le = LabelEncoder()
print(cat)
all_df[cat].fillna("missing", inplace=True)
le = le.fit(all_df[cat])
all_df[cat] = le.transform(all_df[cat])
all_df[cat] = all_df[cat].astype("category")
'AI > preprocessing' 카테고리의 다른 글
| one hot encoding의 이점 (0) | 2024.05.06 |
|---|---|
| sklearn.preproccessing (0) | 2024.04.06 |
| pandas 데이터 시각화 (0) | 2024.03.30 |
| pandas 데이터 확인 (0) | 2024.03.30 |
| keras one hot encoding (0) | 2024.03.21 |