Article

# Apriori Algorithm

, 10 Aug 2012
 Rate this:
Implementation of the Apriori algorithm in C#.

## Introduction

In data mining, Apriori is a classic algorithm for learning association rules. Apriori is designed to operate on databases containing transactions (for example, collections of items bought by customers, or details of a website frequentation).

Other algorithms are designed for finding association rules in data having no transactions (Winepi and Minepi), or having no timestamps (DNA sequencing).

## Overview

The whole point of the algorithm (and data mining, in general) is to extract useful information from large amounts of data. For example, the information that a customer who purchases a keyboard also tends to buy a mouse at the same time is acquired from the association rule below:

Support: The percentage of task-relevant data transactions for which the pattern is true.

Support (Keyboard -> Mouse) =

Confidence: The measure of certainty or trustworthiness associated with each discovered pattern.

Confidence (Keyboard -> Mouse) =

The algorithm aims to find the rules which satisfy both a minimum support threshold and a minimum confidence threshold (Strong Rules).

• Item: article in the basket.
• Itemset: a group of items purchased together in a single transaction.

## How Apriori Works

1. Find all frequent itemsets:
• Get frequent items:
• Items whose occurrence in database is greater than or equal to the min.support threshold.
• Get frequent itemsets:
• Generate candidates from frequent items.
• Prune the results to find the frequent itemsets.
2. Generate strong association rules from frequent itemsets
• Rules which satisfy the min.support and min.confidence threshold.

## Example

A database has five transactions. Let the min sup = 50% and min con f = 80%.

## Solution

### Step 1: Find all Frequent Itemsets

#### Frequent Itemsets

`{A}   {B}   {C}   {E}   {A C}   {B C}   {B E}   {C E}   {B C E}`

## Lattice

Closed Itemset: support of all parents are not equal to the support of the itemset.

Maximal Itemset: all parents of that itemset must be infrequent.

Keep in mind:

Itemset {c} is closed as support of parents (supersets) {A C}:2, {B C}:2, {C D}:1, {C E}:2 not equal support of {c}:3.

And the same for {A C}, {B E} & {B C E}.

Itemset {A C} is maximal as all parents (supersets) {A B C}, {A C D}, {A C E} are infrequent.

And the same for {B C E}.

Software Developer
Australia
Enthusiastic programmer/researcher, passionate to learn new technologies, interested in problem solving,data structures, algorithms and automation.

If you have a question\suggestion about one of my articles, or you want an algorithm implemented in C#, feel free to contact me.

 First PrevNext
 Can I have the C# code Member 10871921 12-Jun-14 3:53
 Re: Can I have the C# code Omar Gameel Salem 12-Jun-14 16:24
 Help me Member 10799788 6-May-14 14:04
 MMAC algorithm Xuan Dung Phu Yen 16-Mar-14 19:15
 do you know? high-utility rule mining? hothi_vuong 14-Mar-14 4:23
 Apriory Algo Implementation Member 10611055 1-Mar-14 0:56
 limit to your code yogeshwarmisal 27-Feb-14 19:32
 Re: limit to your code Omar Gameel Salem 27-Feb-14 21:11
 Apriori Member 10228148 23-Aug-13 6:42
 Apriori variations Saira11 19-Mar-13 3:27
 Apriori algorithm Member 9870300 28-Feb-13 4:24
 Re: Apriori algorithm aspround 18-Apr-13 5:49
 please need help azizhai 12-Jan-13 18:24
 You should add rate. jingjingtr 9-Dec-12 2:40
 New Version is only changed the UI? jingjingtr 5-Dec-12 21:47
 Re: New Version is only changed the UI? Omar Gamil 5-Dec-12 21:53
 Re: New Version is only changed the UI? jingjingtr 5-Dec-12 23:29
 Re: New Version is only changed the UI? friday250f 19-Dec-12 13:16
 Error jingjingtr 2-Dec-12 20:33
 Re: Error Omar Gamil 2-Dec-12 21:00
 Re: Error jingjingtr 3-Dec-12 14:51
 How can i add many items? jingjingtr 2-Dec-12 20:27
 Re: How can i add many items? Omar Gamil 2-Dec-12 21:33
 cSPADE algorithm Marwa M. Ghareeb 26-Nov-12 6:42
 Re: cSPADE algorithm Omar Gamil 26-Nov-12 6:54
 Re: cSPADE algorithm Marwa M. Ghareeb 26-Nov-12 7:43
 Re: cSPADE algorithm Marwa M. Ghareeb 20-Dec-12 5:15
 Re: cSPADE algorithm Omar Gamil 21-Dec-12 9:43
 remerciment LAHCINE ZOZO 23-Nov-12 1:12
 Error in compilation TEITE 22-Oct-12 4:15
 Re: Error in compilation Omar Gamil 22-Oct-12 5:16
 Re: Error in compilation Omar Gamil 22-Oct-12 6:33
 Re: Error in compilation TEITE 22-Oct-12 22:18
 Question about the empty set as premise Mr. Fox 21-Oct-12 2:04
 Re: Question about the empty set as premise Omar Gamil 21-Oct-12 2:15
 Re: Question about the empty set as premise Mr. Fox 21-Oct-12 5:00
 thanks Member 9373709 21-Aug-12 22:55
 Confidence Member 2432696 13-Aug-12 8:30
 My vote of 4 Anindya6023 25-Jul-12 23:17
 Fantastic! However...1 problem Member 9174461 6-Jul-12 12:57
 Re: Fantastic! However...1 problem Omar Gamil 6-Jul-12 13:16
 I need your help ahmedspider2010 5-Jul-12 2:23
 My vote of 5 Perić Željko 2-Jul-12 8:46
 Last Visit: 31-Dec-99 18:00     Last Update: 29-Jul-14 10:42 Refresh 123 Next »