LoslegenKostenlos loslegen

Promoting ebooks with conviction

In the previous exercise, we defined a function to compute conviction. We were asked to apply that function to all two-book permutations of the goodreads-10k dataset. In this exercise, we'll test the function by applying it to the three most popular books, which we used in earlier exercises: The Hunger Games, Harry Potter, and Twilight.

The function has been defined for you and is available as conviction. Recall that it takes an antecedent and a consequent as its two arguments. Additionally, the columns of the books DataFrame from earlier exercises are available as three separate DataFrames: potter, twilight, and hunger.

Diese Übung ist Teil des Kurses

Market Basket Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Compute conviction for {Twilight} \(\rightarrow\) {Potter} and {Potter} \(\rightarrow\) {Twilight}.
  • Compute conviction for {Twilight} \(\rightarrow\) {Hunger} and {Hunger} \(\rightarrow\) {Twilight}.
  • Compute conviction for {Potter} \(\rightarrow\) {Hunger} and {Hunger} \(\rightarrow\) {Potter}.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen