การเพิ่ม Interaction Term ลงใน Basetable
สมมติว่าองค์กรไม่แสวงหากำไรแห่งหนึ่งต้องการจัดแคมเปญในสเปนและฝรั่งเศส และต้องการทราบว่าผู้บริจาครายใดมีแนวโน้มจะบริจาคมากที่สุด โดยมี basetable ที่ประกอบด้วยตัวแปรพยากรณ์ ได้แก่ "age", "country_Spain", "country_France" และตัวแปรเป้าหมาย "target"
เพื่อความสะดวก มีฟังก์ชัน auc ที่คืนค่า AUC จากข้อมูลที่แบ่งพาร์ติชันแล้ว โดยรับอาร์กิวเมนต์ 2 ตัว คือชุดตัวแปรที่ใช้และ basetable:
auc(["variable_1","variable_2"], basetable)
0.51
ในแบบฝึกหัดนี้ จะได้เรียนรู้วิธีเพิ่ม interaction term ลงใน basetable และตรวจสอบว่าส่งผลให้ AUC ของโมเดลพยากรณ์ดีขึ้นหรือไม่
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Predictive Analytics ระดับกลางด้วย Python
คำแนะนำการฝึกหัด
- แสดงค่า AUC ของโมเดลที่ใช้เฉพาะ
ageและค่า AUC ของโมเดลที่ใช้เฉพาะcountry_Spain - แสดงค่า AUC ของโมเดลที่ใช้ทั้ง
ageและcountry_Spain - เพิ่ม interaction term 2 ตัว ได้แก่
ageกับcountry_Spainและageกับcountry_Franceลงใน basetable - แสดงค่า AUC ของโมเดลที่ใช้
age,country_Spainและ interaction term ที่เพิ่มเข้ามา
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Calculate AUC using age only
print(auc(["____"], basetable))
# Calculate AUC using country_Spain only
print(____(["____"], ____))
# Calculate AUC using age and country_Spain
print(____(["____", "____"], ____))
# Add interactions country_Spain x age and country_France x age
basetable["spain_age"] = ____["____"] * ____["____"]
basetable["france_age"] = ____["____"] * ____["____"]
# Calculate AUC using age, country_Spain and interactions
print(____(["____", "____", "____", "____"], ____))