Frequent pattern mining, Association, and Correlations | by Prathibha Perera | Towards Data Science

In Data Mining, Frequent Pattern Mining is a major concern because it is playing a major role in Associations and Correlations. First of all, we should know what is a Frequent Pattern?
Frequent Pattern is a pattern which appears frequently in a data set. By identifying frequent patterns we can observe strongly correlated items together and easily identify similar characteristics, associations among them. By doing frequent pattern mining, it leads to further analysis like clustering, classification and other data mining tasks.
Before moving to mine frequent patterns, we should focus on two terms which “support” and “confidence” because they can provide a measure if the Association rule is qualified or not for a particular data set.
Support: how often a given rule appears in the database being mined
Confidence: the number of times a given rule turns out to be true in practice
Let’s practice it through a sample data set;
Example: One of possible Association Rule is A => D
Total no of Transactions(N) = 5
Frequency(A, D) = > Total no of instances together A with D is 3
Frequency(A) => Total no of occurrence in A
Support = 3 / 5
Confidence = 3 / 4
After getting a clear idea about the two terms Support and Confidence, we can move to frequent pattern mining. Frequent pattern mining, there are 2 categories to be considered,
Mining frequent pattern with candidate generationMining frequent pattern without candidate generation
Mining frequent pattern with candidate generation
Mining frequent pattern without candidate generation
In this article, we are focusing on Mining frequent patterns with candidate generation with Apriori Algorithm which is popularly used for Association mining. Let’s understand Apriori Algorithm with an example and it will help you to understand the concept behind it in a clear manner. Let’s consider the sample data set mentioned above and assume that the minimum support=2.
Generate Candidate set 1, do the first scan and generate One item set
Generate Candidate set 1, do the first scan and generate One item set
In this stage, we get the sample data set and take each individual’s count and make frequent item set 1(K = 1).
“Candidate set 1” figure shows you the individual item Support count. Hence the minimum support is 2 and based on that, item E will remove from the Candidate set 1 as an infrequent item (disqualified).
Frequent itemset based on the minimum support value will be shown under the figure “Frequent item set from the first scan” as the “One item set”.
2. Generate Candidate set 2, do the second scan and generate Second item set
Through this step, you create frequent set 2 (K =2) and takes each of their Support counts.
“Candidate set 2” figure generates through joining Candidate set 1 and takes the frequency of related occurrences. Hence the minimum support is 2, Itemset B, D will be removed from Candidate set 2 as an infrequent item set.
“Frequent item set from the second scan” is the frequent itemset based on the minimum support value and it will generate the “Second item set”.
3. Generate Candidate set 3, do the third scan and generate Third item set
In this iteration create frequent set 3 (K = 3) and take count of Support. Then compare with the minimum support value from the Candidate set 3.
As you can see here we compare Candidate set 3 with the minimum support value, generated Third item set. The frequent set from the third scan is the same as above.
4. Generate Candidate set 4, do the fourth scan and generate Fourth item set
By considering the Frequent set, we can generate Candidate set 4, by joining Candidate set 3. Then possible Candidate set 4 is; [A, B, C, D] which has minimum support less than 2. Therefore we have to stop the calculation from here because we can not go no any more iterations. Therefore for the above data set frequent patterns are [A, B, C] and [A, C, D].
By considering one of the frequent set as{A, B, C} and the possible Association rules as follows;
A => B, CA, B => CA, C => BB => A, CB, C => AC => A, B
A => B, C
A, B => C
A, C => B
B => A, C
B, C => A
C => A, B
Then we assume that the minimum confidence = 50% and calculate each possible Association rules’ Confidence then we can identify disqualified ones with respect to minimum confidence is less than 50%. Then rest of the Association rules which have the Confidence greater or equal to 50% percent those are qualified rules.
As you can see in the Apriori Algorithm, for each step it is generating candidates and it is taking much time when the list of candidates becomes larger.
Now let’s focus on how to do Association using Weka. You can follow the below steps.
Open Weka software and click the “Explore” button.
Open Weka software and click the “Explore” button.
After clicking the “Explorer” button you will get a new window named “Weka Explorer”.
2. Open a preferred data set
Weka Explorer > Preprocess > Open File
By following the above order you can load a data set by selecting an in-built data set or any data set that you want to apply to the Apriori Algorithm.
After opening the selected file you can see the attributes and other statistics under the Preprocess tab. Then you can click the “Edit” button to open the current data set in a Viewer for editing.
♦♦♦♦♦♦♦♦♦ It is important to notice that, your data set includes numerical data you can discretize them using a filter called “Discretize” under the Preprocess tab♦♦♦♦♦♦♦♦♦
3. Go to the Associate tab and choose Apriori, using the choose button.
4. Left click on Apriori and select “Show properties..”
5. Customise the algorithm properties and then click on “Save”
As an example, we can change the number of rules which you obtained from the data set after the Association is done.
6. Click on the “Start” button
♦♦♦♦It is important to notice that you will not enable the “Start” button if it does not have discrete data which is chosen to do Association♦♦♦♦♦♦♦
7. Observe the results
Associator output is as follows and in this case, Algorithm has found the 10 best rules for the provided data set.
This article provides you with some facts that you may know about Frequent pattern mining, Apriori Algorithm, Support, Confidence, and how to proceed with Association through Weka software. Hope this article will help you to enhance your knowledge about the above-mentioned points.
Thank you for reading 🤗 !!!!!
Reference
[1] Ion Lungu, Alexandru Pirjan, Research issues concerning algorithms used for optimizing the data mining process (2010)