การรวมตาราง predictor insight graph ทั้งหมด
ในแบบฝึกหัดก่อนหน้า คุณได้สร้างฟังก์ชันที่คำนวณตาราง predictor insight graph สำหรับตัวแปรที่กำหนด ดังนี้
pig_table = create_pig_table(basetable, "target","variable")
หากต้องการคำนวณตาราง predictor insight graph สำหรับตัวแปรหลายตัวพร้อมกัน แนวทางที่ดีคือเก็บข้อมูลเหล่านั้นไว้ใน dictionary สามารถสร้าง dictionary ใหม่ได้ด้วย dictionary = {} เพิ่มสมาชิกพร้อม key ด้วย dictionary["key"] = value และดึงข้อมูลออกมาโดยใช้ key ด้วย print(dictionary["key"])
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เชิงพยากรณ์เบื้องต้นด้วย Python
คำแนะนำการฝึกหัด
- สร้าง dictionary ว่างชื่อ
pig_tables - สำหรับแต่ละตัวแปร ให้สร้างตาราง predictor insight graph
- สำหรับแต่ละตัวแปร ให้เพิ่มตาราง predictor insight graph นั้นลงใน dictionary โดยใช้ชื่อตัวแปรเป็น key
- แสดงผลตาราง predictor insight graph ของ
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["____"])