Session Ready
Exercise

Applying Zhang's metric

The founder of the ebook start-up has returned for additional consulting services. She has sent you a list of itemsets she's investigating and has asked you to determine whether any of them contain items that are dissociated. When you're finished, she has asked that you add the metric you use to a column in the rules DataFrame, which is available to you, and currently contains columns for antecedents and consequents.

The itemsets are available as a list of lists called itemsets. Each list contains the antecedent first and the consequent second. You also have access to the books DataFrame from previous exercises. Note that Zhang's metric has been defined for you and is available as zhang(). Additionally, pandas is available as pd and numpy as np.

Instructions
100 XP
  • Loop over each itemset in itemsets.
  • Extract the antecedent and consequent columns from books for each itemset.
  • Complete the statement and append it to the zhangs_metric list.
  • Print the metric for each itemset.