开始使用免费开始使用

评估 BMI 结果

对于 BMI 位于最高 10% 与最低 10% 的患者,预测的疾病进展(响应变量 y)有何差异?您将使用对多元正态分布进行采样的模拟结果来回答这个问题!

模拟已经为您运行完成:您的任务是评估 df_results 中的模拟结果。

以下库已为您导入:pandaspdnumpynp,以及 scipy.statsst

本练习是课程的一部分

Python 中的蒙特卡洛模拟

查看课程

练习说明

  • 使用 np.quantile() 计算模拟结果中 bmi 的第 10 分位数和第 90 分位数,分别保存为 bmi_q10bmi_q90
  • 使用 bmi_q10bmi_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)
编辑并运行代码