Finding association rules

In order to find the association rules, we have to first search for all of the rules that have support greater than the threshold support. But the question arises: how do we find these? A possible way to find this is by brute force, which means to list all the possible association rules and calculate the support and confidence for each rule. Later, remove all the rules that fail the confidence and support thresholds.

Given there are n items in the set I, the total number of possible association rules is 3n - 2n+1 + 1.

If X is a frequent itemset with k elements, then there are 2k - 2 association rules.

Let's see how to execute association rules in Python:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

data = pd.read_csv('association_mining.csv', header = None)

transactions = []
for i in range(0, 7501):
transactions.append([str(data.values[i,j]) for j in range(0, 20)])

If we are asking for an item to appear three times in a day for seven days' time, the support will be 3 x 7/7051. 7051 is the total number of transactions. We will keep the confidence as 20% in the beginning:

from apyori import apriori
rules = apriori(transactions, min_support = 0.003, min_confidence = 0.2, min_lift = 3, min_length = 2)

results = list(rules)
results

We can visualize the output by running the results command from the preceding code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.205.136