변수 정규화하기
이제 데이터 준비의 마지막 단계입니다. 왜도 보정을 마친 데이터셋 wholesale_boxcox를 같은 스케일로 변환해, 모든 열의 평균이 0이고 표준편차가 1이 되도록 하세요. 이를 위해 sklearn.preprocessing 모듈의 StandardScaler 함수를 사용합니다.
이전 연습 문제에서 변환한 왜도 보정 데이터셋 wholesale_coxbox는 pandas DataFrame으로 불러와져 있습니다. 또한 StandardScaler() 인스턴스는 scaler로 초기화되어 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 마케팅용 Machine Learning
연습 안내
- 초기화된
scaler인스턴스를 Box-Cox 변환된 데이터셋에 대해 fit하세요. - 변환을 수행하고 결과를
wholesale_scaled로 저장하세요. - 스케일된 데이터셋으로부터
pandasDataFrame을 생성하세요. - 모든 열에 대해 평균과 표준편차를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Fit the initialized `scaler` instance on the Box-Cox transformed dataset
scaler.___(wholesale_boxcox)
# Transform and store the scaled dataset as `wholesale_scaled`
wholesale_scaled = scaler.___(wholesale_boxcox)
# Create a `pandas` DataFrame from the scaled dataset
wholesale_scaled_df = pd.DataFrame(data=___,
index=wholesale_boxcox.___,
columns=wholesale_boxcox.columns)
# Print the mean and standard deviation for all columns
print(wholesale_scaled_df.agg(['___','std']).round())