Get startedGet started for free

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.

This exercise is part of the course

Market Basket Analysis in Python

View Course

Exercise instructions

  • 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}.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)
Edit and Run Code