# Apriori Algorithm in Data Mining with examples

## Apriori Algorithm in Data Mining with examples

Apriori Helps in mining the frequent itemset.

## Example of Apriori Algorithm

Let’s see an example of the Apriori Algorithm.

Minimum Support: 2

Step 1: Data in the database

Step 2: Calculate the support/frequency of all items

Step 3: Discard the items with minimum support less than 2

Step 4: Combine two items

Step 5: Calculate the support/frequency of all items

Step 6: Discard the items with minimum support less than 2

Step 6.5:Â Combine three items and calculateÂ their support.

Step 7: Discard the items with minimum support less than 2

Result:

Only one itemset is frequent (Eggs, Tea, Cold Drink) because this itemset has minimum support 2Â

## Example 2 of Apriori Algorithm

Let’s see another example of the Apriori Algorithm.

Minimum Support :3

Step 1: Data in the database

Step 2: Calculate the support/frequency of all items

Step 3: Discard the items with minimum support less thanÂ 3

Step 4: Combine two items

Step 5: Calculate the support/frequency of all items

Step 6: Discard the items with minimum support less thanÂ 3

Step 6.5:Â Combine three items and calculateÂ their support.

Step 7: Discard the items with minimum support of less than 3. So all itemsets are excluded except “Eggs, Cold drink” because this itemset has the support of 3.

Result:

There is no frequent itemset because all itemsets have minimum support of less than 3.

## Advantages of Â Apriori Algorithm

Apriori Algorithm is the simplest and easy to understand the algorithm for mining the frequent itemset.

Apriori Algorithm is fully supervised.

Apriori Algorithm is fully supervised so it does not require labeled data.

Apriori Algorithm is an exhaustive algorithm, so it gives satisfactory results to mine all the rules within specified confidence and sport.

## Apriori principles

### Downward closure property of frequent patterns

Downward closure property of frequent patterns, means that All subset of any frequent itemset must also be frequent.

#### Example of Downward closure property

If Notebook, Pencil, School BagÂ is a frequent itemset, then we can say that all of the following itemsets are frequent;

• Notebook
• Pencil
• School Bag
• Notebook, Â Pencil
• Notebook, School Bag
• Pencil, School Bag

### Apriori pruning principle

If an itemset is infrequent, its superset should not be generated for getting the frequent itemset.

#### Examples ofÂ Apriori pruning principle

If Notebook, PencilÂ is a frequent itemset and School Bag is not frequent itemset, then we can say that all of the following itemsets are frequent;

• Notebook
• Pencil
• Notebook, Pencil

## Apriori Candidates generation

Candidates can be generated by the self joining and Apriori pruning principles.

Step 1:

### Self-joining of Apriori Candidates

#### Example ofÂ self-joining

A1 B1 C1 D1 E1

C1={A1 B1 C1, Â  Â A1 B1 D1, Â  Â A1 C1 D1, Â  Â A1 C1 E1, Â  Â B1 C1 D1}

Self-joining =Â C1Â * C1A1 Â B1 C1 D1Â from A1 B1 C1Â and A1 B1 D1A1 C1 Â D1 Â E1Â from A1 C1 D1Â and A1 C1 E1

So frequent candidates areÂ A1 Â B1 C1 D1Â  andÂ A1 C1 Â D1 Â E1

Step 2:Â

### Apriori pruning principle

#### Example ofÂ Apriori pruning principle

A1 B1 C1 D1 E1C1={A1 B1 C1, Â  Â A1 B1 D1, Â  Â A1 C1 D1, Â  Â A1 C1 E1, Â  Â B1 C1 D1}Â According to Apriori Pruning principle A1 C1 D1 E1Â is remoA1ed because A1 D1 E1Â is not in C1.Â

So frequent candidate is A1 B1 C1 D1

## Important interview questions of Â Apriori Algorithm

Let’s see some important interview questions of Â Apriori Algorithm.

1. Â What are the frequent itemsets?
2. Â What is the apriori algorithm?
3. Â What is the role of the apriori algorithm in data mining?
4. Â Give some examples of the apriori algorithm in data mining.
5. Â What are the advantages of the apriori algorithm?
6. Â What are the disadvantages of the apriori algorithm?
7. Â How does the Apriori algorithm help in mining the frequent itemset?
8. Â What is Apriori pruning principle?
9. How we can generate the Apriori candidates?
10. What is self joining of candidates in Apriori?

## Implementation of the Apriori Algorithm in C++

This is the demoÂ  of Apriori algorithmÂ  in which we are taking the list of 5 lists of purchases items and getting the result of apriori.

Output

## Next Similar Tutorials

1. Frequent pattern Mining, Closed frequent itemset, max frequent itemset in data mining – Click Here
2. Support, Confidence, Minimum support, Frequent itemset, K-itemset, absolute support in data mining – Click Here