開始使用免費開始

彙整所有預測因子洞見圖表格

在前一個練習中,你撰寫了一個函式,能夠針對指定變數計算預測因子洞見圖表格,如下所示:

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["____"])
編輯並執行程式碼