Session Ready
Exercise

Computing conviction with a function

After successful completion of her trial project, the ebook start-up's founder decides to hire you for a much bigger project. She asks you if you are able to compute conviction for every pair of books in the goodreads-10k dataset, so she can use that information to decide which books to locate closer together on the website.

You agree to take the job, but realize that you need more a efficient way to compute conviction, since you will need to compute it many times. You decide to write a function that computes it. It will take two columns of a pandas DataFrame as an input, one antecedent and one consequent, and output the conviction metric. Note that pandas is available as pd and numpy is available as np.

Instructions
100 XP
  • Compute the support for the antecedent and assign it to supportA.
  • Compute the support for NOT consequent.
  • Compute the support for antecedent and NOT consequent.