การสร้างตาราง predictor insight graph
ในแบบฝึกหัดก่อนหน้า คุณได้เรียนรู้วิธีคำนวณคอลัมน์ incidence ของตาราง predictor insight graph แล้ว ในแบบฝึกหัดนี้ จะเพิ่มขนาดของแต่ละกลุ่มเข้าไปด้วย และรวมทุกอย่างไว้ในฟังก์ชันที่คืนค่าตาราง predictor insight graph สำหรับตัวแปรที่กำหนด
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เชิงพยากรณ์เบื้องต้นด้วย Python
คำแนะนำการฝึกหัด
- จัดกลุ่ม basetable ตาม
variable - คำนวณตาราง predictor insight graph โดยคำนวณค่า target incidence และขนาดของแต่ละกลุ่ม
- ใช้ฟังก์ชัน
create_pig_tableเพื่อคำนวณตาราง predictor insight graph สำหรับตัวแปร "gender"
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Function that creates predictor insight graph table
def create_pig_table(basetable, target, variable):
# Create groups for each variable
groups = basetable[[target,variable]].____(____)
# Calculate size and target incidence for each group
pig_table = groups[____].agg(Incidence = '____', Size = '____').reset_index()
# Return the predictor insight graph table
return pig_table
# Calculate the predictor insight graph table for the variable gender
pig_table_gender = ____(basetable, "target", ____)
# Print the result
print(pig_table_gender)