MulaiMulai sekarang secara gratis

Further refinement with lift

Once again, you report your results to the library: Use Twilight to promote Harry Potter, since the rule has a higher confidence metric. The library thanks you for the suggestion, but asks you to confirm that this is a meaningful relationship using another metric.

You recall that lift may be useful here. If lift is less than 1, this means that Harry Potter and Twilight are paired together less frequently than we would expect if the pairings occurred by random chance. As with the previous two exercises, the DataFrame books has been imported for you, along with numpy under the alias np.

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 lift of {Potter} \(\rightarrow\) {Twilight}.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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

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

# Compute support for Twilight
supportT = ____.mean()

# Compute lift
lift = ____ / (supportP * ____)

# Print lift
print("Lift: %.2f" % lift)
Edit dan Jalankan Kode