Running Apriori
And finally, this is how we use the algorithm with our toy example:
let transactions = [["", "", "", ""], ["", "", ""], ["", "", ""], ["", ""], ["", ""], ["", ""], [""] ] let apriori = Apriori<String>(transactions: transactions) let rules = apriori.associationRules(minSupport: 0.3, minConfidence: 0.5) for rule in rules { print(rule) print("Confidence: ", apriori.confidence(rule), "Lift: ", apriori.lift(rule), "Conviction: ", apriori.conviction(rule)) }
It produces the following:
{ → } Confidence: 0.8 Lift: 1.4 Conviction: 2.14285714285714 { → } Confidence: 1.0 Lift: 1.4 Conviction: inf { → } Confidence: 0.75 Lift: 1.3125 Conviction: 1.71428571428571 { → } Confidence: 0.75 Lift: 1.3125 Conviction: 1.71428571428571
Let's analyze what's going on here. The second rule has the maximum confidence as well as conviction...