开始使用免费开始使用

确定变量的加入顺序

前向逐步变量选择从一个空的变量集合开始,逐个加入预测变量。每一步都会在当前变量集合的基础上,选择与之组合后 AUC 最高的预测变量。

在本练习中,您将学习如何实现前向逐步变量选择。为此,您可以使用已为您实现的 next_best 函数。用法如下:

next_best(current_variables,candidate_variables,target,basetable)

其中,current_variables 是当前已在模型中的变量列表,candidate_variables 是下一步可加入的变量列表。

本练习是课程的一部分

Python 预测分析入门

查看课程

练习说明

  • 使用函数 next_best 计算下一个最优变量,并将其赋给 next_variable
  • 更新 current_variables 列表。
  • 更新 candidate_variables 列表。

交互式实操练习

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

# Find the candidate variables
candidate_variables = list(basetable.columns.values)
candidate_variables.remove("target")

# Initialize the current variables
current_variables = []

# The forward stepwise variable selection procedure
number_iterations = 5
for i in range(0, number_iterations):
    next_variable = ____(____, ____, ["target"], basetable)
    current_variables = current_variables + [____]
    candidate_variables.remove(____)
    print("Variable added in step " + str(i+1)  + " is " + next_variable + ".")
print(current_variables)
编辑并运行代码