Session Ready
Exercise

Defining Zhang's metric

In general, when we want to perform a task many times, we'll write a function, rather than coding up each individual instance. In this exercise, we'll define a function for Zhang's metric that takes an antecedent and consequent and outputs the metric itself. When the problems we solve become increasingly complicated in the following chapter, having a convenient means of computing a metric will greatly simplify things.

Note that numpy has been imported as np and pandas has been imported as pd. Additionally, recall that the expression for Zhang's metric in terms of support calculations is the following:

$$Zhang(A \rightarrow B) = $$ $$\frac{Support(A \& B) - Support(A) Support(B)}{ max[Support(AB) (1-Support(A)), Support(A)(Support(B)-Support(AB))]}$$

Instructions
100 XP
  • Define the support values of the antecedent and consequent individually.
  • Define the support of {antecedent, consequent}.
  • Complete the expressions for the numerator and denominator.
  • Complete the expression for Zhang's metric.