MulaiMulai sekarang secara gratis

Refining support with confidence

After reporting your findings from the previous exercise, the library asks you about the direction of the relationship. Should they use Harry Potter to promote Twilight or Twilight to promote Harry Potter?

After thinking about this, you decide to compute the confidence metric, which has a direction, unlike support. You'll compute it for both {Potter} \(\rightarrow\) {Twilight} and {Twilight} \(\rightarrow\) {Potter}. The DataFrame books has been imported for you, which has one column for each book: Potter and Twilight.

Latihan ini adalah bagian dari kursus

Market Basket Analysis in Python

Lihat Kursus

Petunjuk latihan

  • Compute the support of {Potter, Twilight}.
  • Compute the support of {Potter}.
  • Compute the support of {Twilight}.
  • Compute the confidence of {Potter} \(\rightarrow\) {Twilight} and {Twilight} \(\rightarrow\) {Potter}.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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))
Edit dan Jalankan Kode