BMI 결과 평가하기
BMI가 상위 10%인 환자와 하위 10%인 환자 사이에서 예측된 질병 진행 정도(반응 변수 y)는 얼마나 차이가 날까요? 이 질문에 답하기 위해 다변량 정규분포에서 샘플링한 시뮬레이션 결과를 활용할 거예요!
시뮬레이션은 이미 완료되어 있어요. 여러분의 과제는 df_results에 담긴 시뮬레이션 결과를 평가하는 것입니다.
다음 라이브러리는 이미 임포트되어 있어요: pandas는 pd, numpy는 np, scipy.stats는 st.
이 연습은 강의의 일부입니다
Python으로 배우는 Monte Carlo 시뮬레이션
연습 안내
np.quantile()을 사용해 시뮬레이션 결과의bmi에 대해 10번째와 90번째 분위수를 계산하고, 각각bmi_q10,bmi_q90에 저장하세요.bmi_q10과bmi_q90을 사용해df_summary를 필터링하고, 예측된 y 값을 구하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
simulation_results = st.multivariate_normal.rvs(mean=mean_dia, size=20000, cov=cov_dia)
df_results = pd.DataFrame(simulation_results,columns=["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"])
predicted_y = regr_model.predict(df_results)
df_y = pd.DataFrame(predicted_y, columns=["predicted_y"])
df_summary = pd.concat([df_results,df_y], axis=1)
# Calculate the 10th and 90th quantile of bmi in the simulated results
bmi_q10 = np.quantile(df_summary["bmi"], ____)
bmi_q90 = np.quantile(df_summary["bmi"], ____)
# Use bmi_q10 and bmi_q90 to filter df_summary and obtain predicted y values
mean_bmi_q90_outcome = np.mean(df_summary[____]["predicted_y"])
mean_bmi_q10_outcome = np.mean(df_summary[____]["predicted_y"])
y_diff = mean_bmi_q90_outcome - mean_bmi_q10_outcome
print(y_diff)