开始使用免费开始使用

相关变量

加入模型的前 10 个变量如下:

['max_gift', 'number_gift', 'time_since_last_gift', 'mean_gift', 'income_high', 'age', 'country_USA', 'gender_F', 'income_low', 'country_UK']

如您所见,min_gift 并未被加入。这是否意味着它是一个不好的变量?您可以通过将其作为单一变量用于模型并计算 AUC 来检验该变量的表现。min_gift 的 AUC 与 income_high 的 AUC 相比如何?为此,您可以使用函数 auc()

auc(variables, target, basetable)

有时一个好的变量不会被加入,是因为它与已在模型中的变量高度相关。您可以通过计算这些变量之间的相关性来检验这一点:

import numpy
numpy.corrcoef(basetable["variable_1"],basetable["variable_2"])[0,1]

本练习是课程的一部分

Python 预测分析入门

查看课程

练习说明

  • 仅使用变量 min_gift 计算模型的 AUC。
  • 仅使用变量 income_high 计算模型的 AUC。
  • 计算变量 min_giftmean_gift 之间的相关性。

交互式实操练习

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

import numpy as np

# Calculate the AUC of the model using min_gift only
auc_min_gift = auc([____], ["target"], ____)
print(round(auc_min_gift,2))

# Calculate the AUC of the model using income_high only
auc_income_high = ____([____], [____], ____)
print(round(auc_income_high,2))

# Calculate the correlation between min_gift and mean_gift
correlation = np.corrcoef(basetable["____"], basetable["____"])[0,1]
print(round(correlation,2))
编辑并运行代码