# 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.

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 D1According 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