เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

โปรโมต e-book ด้วย conviction

ในแบบฝึกหัดก่อนหน้า เราได้กำหนดฟังก์ชันสำหรับคำนวณ conviction และนำไปใช้กับ permutation ของหนังสือสองเล่มทุกคู่ในชุดข้อมูล goodreads-10k ในแบบฝึกหัดนี้ เราจะทดสอบฟังก์ชันดังกล่าวโดยนำไปใช้กับหนังสือยอดนิยม 3 เล่มที่เคยใช้ในแบบฝึกหัดก่อนหน้า ได้แก่ The Hunger Games, Harry Potter และ Twilight

ฟังก์ชันถูกกำหนดไว้ให้แล้ว และพร้อมใช้งานในชื่อ conviction โดยรับ antecedent และ consequent เป็นอาร์กิวเมนต์สองตัว นอกจากนี้ คอลัมน์จาก DataFrame books ในแบบฝึกหัดก่อนหน้ายังพร้อมใช้งานในรูปแบบ DataFrame แยกกันสามตัว ได้แก่ potter, twilight และ hunger

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Market Basket Analysis ด้วย Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • คำนวณ conviction สำหรับ {Twilight} \(\rightarrow\) {Potter} และ {Potter} \(\rightarrow\) {Twilight}
  • คำนวณ conviction สำหรับ {Twilight} \(\rightarrow\) {Hunger} และ {Hunger} \(\rightarrow\) {Twilight}
  • คำนวณ conviction สำหรับ {Potter} \(\rightarrow\) {Hunger} และ {Hunger} \(\rightarrow\) {Potter}

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Compute conviction for twilight -> potter and potter -> twilight
convictionTP = conviction(twilight, potter)
convictionPT = conviction(____, twilight)

# Compute conviction for twilight -> hunger and hunger -> twilight
convictionTH = conviction(____, ____)
convictionHT = ____(hunger, twilight)

# Compute conviction for potter -> hunger and hunger -> potter
convictionPH = ____(potter, hunger)
convictionHP = ____

# Print results
print('Harry Potter -> Twilight: ', convictionHT)
print('Twilight -> Potter: ', convictionTP)
แก้ไขและรันโค้ด