대치값 시각화하기
대치값을 분석하고 최적의 방법을 고르는 일은 많은 실험을 필요로 합니다. 대치하는 과정에서 데이터에 편향이 생기지 않도록 하는 것이 중요해요. 이전 두 연습 문제에서 평균, 중앙값, 최빈값, 상수 대치로 4가지 다른 대치값을 만들었습니다.
이번 연습 문제에서는 앞에서 대치한 DataFrame의 산점도를 만들어 보겠습니다. 이를 위해 제목을 키로 사용하는 딕셔너리를 만들어 각 DataFrame을 담을 거예요.
diabetes_mean, diabetes_median, diabetes_mode, diabetes_constant DataFrame은 이미 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python에서 결측치 다루기
연습 안내
- 2행 2열의 플롯으로 4개의 서브플롯을 만드세요.
- 각 제목을 키로, 해당하는 DataFrame을 값으로 매핑하여
imputations딕셔너리를 만드세요. axes와imputations를 함께 순회하며imputations의 각 DataFrame을 그리세요.- 색상은
nullity로 설정하고, 각 서브플롯의 제목은 해당 대치 방법의 이름으로 지정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Set nrows and ncols to 2
fig, axes = plt.subplots(nrows=___, ncols=___, figsize=(10, 10))
nullity = diabetes.Serum_Insulin.isnull()+diabetes.Glucose.isnull()
# Create a dictionary of imputations
imputations = {'Mean Imputation': ___, 'Median Imputation': ___,
'Most Frequent Imputation': ___, 'Constant Imputation': ___}
# Loop over flattened axes and imputations
for ax, df_key in zip(___.___(), ___):
# Select and also set the title for a DataFrame
imputations[___].plot(x='Serum_Insulin', y='Glucose', kind='scatter',
alpha=0.5, c=___, cmap='rainbow', ax=ax,
colorbar=False, title=___)
plt.show()