評估 BMI 與 HDL 的結果
對於同時位於 BMI 前 10% 且 HDL 前 25% 的病人,相較於同時位於 BMI 後 10% 且 HDL 後 25% 的病人,其預測的疾病進展(反應變數 y)相差多少?同樣地,我們已經替你完成模擬;你的任務是評估 df_results 中的模擬結果,找出這個問題的答案!
已匯入下列函式庫:pandas 作為 pd、numpy 作為 np,以及 scipy.stats 作為 st。
本練習屬於課程
Python 的 Monte Carlo 模擬
練習說明
- 完成平均結果的定義:先篩選同時位於 BMI 前 10% 且 HDL 前 25% 的病人,再篩選同時位於 BMI 後 10% 且 HDL 後 25% 的病人。請使用已替你定義好的
hdl_q25、hdl_q75、bmi_q10、bmi_q90。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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)
hdl_q25 = np.quantile(df_summary["hdl"], 0.25)
hdl_q75 = np.quantile(df_summary["hdl"], 0.75)
bmi_q10 = np.quantile(df_summary["bmi"], 0.10)
bmi_q90 = np.quantile(df_summary["bmi"], 0.90)
# Complete the mean outcome definitions
bmi_q90_hdl_q75_outcome = np.mean(df_summary[(df_summary["bmi"] > bmi_q90) & (____)]____)
bmi_q10_hdl_q15_outcome = np.mean(df_summary[(df_summary["bmi"] < bmi_q10) & (____)]____)
y_diff = bmi_q90_hdl_q75_outcome - bmi_q10_hdl_q15_outcome
print(y_diff)