开始使用免费开始使用

选择下一个最优变量

前向逐步变量选择从一个空的变量集合开始,分步进行,每一步都会加入当前最优的下一个变量。为帮助您实现这一过程,我们已为您实现了两个便捷函数。

auc 函数会针对给定的变量集合 variables,计算使用该变量集合作为自变量的模型的 AUC。next_best 函数会计算在下一步应将哪个变量加入变量列表。

在本练习中,您将通过这些函数来加深理解。您将计算给定变量集合的 AUC,计算下一步应加入的变量,并验证这样确实能够得到最优的 AUC。

本练习是课程的一部分

Python 预测分析入门

查看课程

练习说明

  • auc 函数已为您实现。计算将 "max_gift""mean_gift""min_gift" 作为自变量的模型的 AUC。请将这些变量以列表形式作为 auc 函数的第 1 个参数传入。
  • next_best 函数已为您实现。已知当前模型包含 "max_gift""mean_gift""min_gift",候选自变量为 "age""gender_F"。请计算下一步应加入哪个变量。next_best 的第 1 个参数是当前变量的列表,第 2 个参数是候选自变量的列表。
  • 计算将 "max_gift""mean_gift""min_gift""age" 作为自变量的模型的 AUC。
  • 计算将 "max_gift""mean_gift""min_gift""gender_F" 作为自变量的模型的 AUC。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Calculate the AUC of a model that uses "max_gift", "mean_gift" and "min_gift" as predictors
auc_current = ____([____, ____, ____], ["target"], basetable)
print(round(auc_current,4))

# Calculate which variable among "age" and "gender_F" should be added to the variables "max_gift", "mean_gift" and "min_gift"
next_variable = ____([____, ____, ____], [____, ____], ["target"], basetable)
print(next_variable)

# Calculate the AUC of a model that uses "max_gift", "mean_gift", "min_gift" and "age" as predictors
auc_current_age = ____([____, ____, ____, ____], ["target"], basetable)
print(round(auc_current_age,4))

# Calculate the AUC of a model that uses "max_gift", "mean_gift", "min_gift" and "gender_F" as predictors
auc_current_gender_F = ____([____], ["target"], basetable)
print(round(auc_current_gender_F,4))
编辑并运行代码