인프런 커뮤니티 질문&답변
레이블인코딩 (카테고리)
작성
·
10
0
초보자 질문 드립니다.
퇴근후 딴짓님의 빅분기 실기책 이직여부 예측 문제(p.294)관련 질문입니다.
# 레이블 인코딩
from sklearn.preprocessing import LabelEncoder
combined = pd.concat([train, test])
cols = train.select_dtypes(include='object').columns
for col in cols:
le = LabelEncoder()
combined[col] = le.fit_transform(combined[col])
n_train = len(train)
train = combined[:n_train]
test = combined[n_train:]코드 위에서 세번째 줄, cols 불러올 때 combined이 아닌 train 으로 한 이유가 궁금합니다.
train 해도 문제 없는건가요?
train, test 범주형 데이터 비교 시, city만 '카테고리 동일하지 않음' 나옴
아래 코드로 카테고리 수 추출하면, train['city'] 123개 > test['city'] 113개
print("\n ===== train/test 카테고리별 수 =====")
print(train.nunique())
print(test.nunique())개수는 train이 더 많지만 카테고리가 동일하지 않은데.. combined이 맞는건지 고견 부탁드립니다ㅠ
답변
답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!




