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

เพิ่มความแม่นยำด้วย confidence

หลังจากรายงานผลจากแบบฝึกหัดที่แล้ว ห้องสมุดต้องการทราบว่าความสัมพันธ์นี้มีทิศทางอย่างไร ควรใช้ Harry Potter เพื่อโปรโมต Twilight หรือใช้ Twilight เพื่อโปรโมต Harry Potter?

เมื่อพิจารณาแล้ว คุณตัดสินใจคำนวณเมตริก confidence ซึ่งมีทิศทาง ต่างจาก support ที่ไม่มี โดยจะคำนวณทั้งสองทิศทาง คือ {Potter} \(\rightarrow\) {Twilight} และ {Twilight} \(\rightarrow\) {Potter} DataFrame ชื่อ books ได้ถูกนำเข้าให้แล้ว ซึ่งมีหนึ่งคอลัมน์สำหรับแต่ละเล่ม ได้แก่ Potter และ Twilight

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

Market Basket Analysis ด้วย Python

ดูคอร์ส

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

  • คำนวณ support ของ {Potter, Twilight}
  • คำนวณ support ของ {Potter}
  • คำนวณ support ของ {Twilight}
  • คำนวณ confidence ของ {Potter} \(\rightarrow\) {Twilight} และ {Twilight} \(\rightarrow\) {Potter}

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

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

# Compute support for Potter and Twilight
supportPT = np.logical_and(____, ____).mean()

# Compute support for Potter
supportP = books['Potter'].____

# Compute support for Twilight
supportT = ____

# Compute confidence for both rules
confidencePT = supportPT / ____
confidenceTP = ____ / supportT

# Print results
print('{0:.2f}, {1:.2f}'.format(confidencePT, confidenceTP))
แก้ไขและรันโค้ด