开始使用免费开始使用

汇总所有预测因子洞察图表

在上一个练习中,您实现了一个函数,用于为给定变量计算预测因子洞察图表对应的表,如下所示:

pig_table = create_pig_table(basetable, "target","variable")

如果您想一次为多个变量计算预测因子洞察图表,建议将结果存入字典。您可以使用 dictionary = {} 创建一个新字典,使用 dictionary["key"] = value 通过键添加元素,并使用键 print(dictionary["key"]) 取回元素。

本练习是课程的一部分

Python 预测分析入门

查看课程

练习说明

  • 创建一个空字典 pig_tables
  • 为每个变量创建一个预测因子洞察图表对应的表。
  • 将每个变量的该表添加到字典中,键为该变量的名称。
  • 打印 disc_time_since_last_gift 的预测因子洞察图表对应的表。

交互式实操练习

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

# Create the list of variables for our predictor insight graph tables
variables = ["income","gender","disc_mean_gift","disc_time_since_last_gift"]

# Create an empty dictionary
pig_tables = ____

# Loop through the variables
for variable in variables:
  
    # Create a predictor insight graph table
    pig_table = ____(basetable, ____, ____)
    
    # Add the table to the dictionary
    pig_tables[____] = ____

# Print the predictor insight graph table of the variable "disc_time_since_last_gift"
print(pig_tables["____"])
编辑并运行代码