Đánh giá kết quả BMI
Sự khác biệt trong dự đoán mức độ tiến triển bệnh (biến phản hồi, y) giữa nhóm bệnh nhân thuộc top 10% BMI so với nhóm thấp nhất 10% BMI là bao nhiêu? Bạn sẽ dùng kết quả của mô phỏng lấy mẫu từ phân phối chuẩn đa biến để trả lời câu hỏi này!
Mô phỏng đã được thực hiện sẵn cho bạn: nhiệm vụ của bạn là đánh giá kết quả mô phỏng trong df_results.
Các thư viện sau đã được nhập sẵn: pandas là pd, numpy là np, và scipy.stats là st.
Bài tập này là một phần của khóa học
Mô phỏng Monte Carlo với Python
Hướng dẫn bài tập
- Dùng
np.quantile()để tính các phân vị 10% và 90% củabmitrong kết quả mô phỏng, lưu vàobmi_q10vàbmi_q90. - Dùng
bmi_q10vàbmi_q90để lọcdf_summaryvà lấy các giá trị y dự đoán.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu nà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)