수치형 열과 범주형 열 분리하기
이전 연습 문제에서 데이터셋의 특성을 살펴보았고, 이제 데이터 전처리를 진행할 준비가 되었어요. 이번에는 telco_raw DataFrame에서 사용자 지정 임계값(범주형 vs. 수치형의 고유값 개수 기준)에 따라 범주형 변수와 수치형 변수를 분리해 볼게요. pandas 모듈은 pd로 로드되어 있어요.
원시 통신사 이탈 데이터셋 telco_raw는 pandas DataFrame으로 로드되어 있어요. 콘솔에서 탐색해 보며 데이터셋에 익숙해지세요.
이 연습은 강의의 일부입니다
Python으로 배우는 마케팅용 Machine Learning
연습 안내
customerID와Churn열 이름을 저장하세요.- 고유값 개수가 5 미만인 열 이름을
categorical에 할당하세요. - 리스트에서
target을 제거하세요. numerical에는custid,target,categorical에 포함되지 않은 모든 열 이름을 할당하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Store customerID and Churn column names
custid = ['___']
target = ['___']
# Store categorical column names
categorical = telco_raw.___()[telco_raw.nunique() < ___].keys().tolist()
# Remove target from the list of categorical variables
categorical.remove(___[0])
# Store numerical column names
numerical = [x for x in telco_raw.___ if x not in custid + ___ + categorical]