AI/preprocessing
pandas preproccessing
bitpoint
2024. 4. 6. 12:46
카테고리로 분류하고, 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")