14,971,296 members
Articles / Programming Languages / C#
Article
Posted 2 Apr 2010

515.1K views
149 bookmarked

# Apriori Algorithm

Rate me:
4.91/5 (84 votes)
10 Aug 2012CPOL2 min read
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}.

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Software Developer Egypt
Enthusiastic programmer/researcher, passionate to learn new technologies, interested in problem solving, data structures, algorithms, AI, machine learning and nlp.

Amateur guitarist/ keyboardist, squash player.

## Comments and Discussions

 First PrevNext
 Hi Shubhangi Sohoni30-Jun-21 1:59 Shubhangi Sohoni 30-Jun-21 1:59
 Code of the program Member 1434841429-Apr-19 20:40 Member 14348414 29-Apr-19 20:40
 apriori code Member 1419967827-Mar-19 4:04 Member 14199678 27-Mar-19 4:04
 Permission to use in a book Member 135974389-Apr-18 1:03 Member 13597438 9-Apr-18 1:03
 appriori Member 135897194-Apr-18 19:06 Member 13589719 4-Apr-18 19:06
 Apriori Algorithm ibrahimreyad10-Nov-17 12:16 ibrahimreyad 10-Nov-17 12:16
 Apriori java code Member 1312130611-Apr-17 3:58 Member 13121306 11-Apr-17 3:58
 apriori with java please Member 1311902110-Apr-17 9:35 Member 13119021 10-Apr-17 9:35
 Help me with apriori algorithm Member 1292966731-Dec-16 18:22 Member 12929667 31-Dec-16 18:22
 java code please Member 1290059012-Dec-16 8:24 Member 12900590 12-Dec-16 8:24
 REQUEST FOR APRIORI ALGORITHM Member 1273717015-Oct-16 2:39 Member 12737170 15-Oct-16 2:39
 REQUEST FOR APRIORI ALGORITHM Member 1273717015-Oct-16 2:37 Member 12737170 15-Oct-16 2:37
 Help me! Fan KARIK23-May-16 0:01 Fan KARIK 23-May-16 0:01
 You can send me form of Apriori Algorithm...I don't understand for it
 Regarding apriori algorithm in java Member 1236742222-Mar-16 7:26 Member 12367422 22-Mar-16 7:26
 request for java code for apriori implementation Member 123791628-Mar-16 18:29 Member 12379162 8-Mar-16 18:29
 Custom built Apriori algorithm shuga24-Nov-15 8:29 shuga 24-Nov-15 8:29
 Re: Custom built Apriori algorithm Omar Gameel Salem24-Nov-15 13:03 Omar Gameel Salem 24-Nov-15 13:03
 Re: Custom built Apriori algorithm shuga24-Nov-15 22:07 shuga 24-Nov-15 22:07
 can you please send me the apriori algorithm implemented in c++ Member 1213767613-Nov-15 7:22 Member 12137676 13-Nov-15 7:22
 can i get c# full code Prabasini3-Nov-15 10:03 Prabasini 3-Nov-15 10:03
 Apriori in C# Member 1199820920-Sep-15 10:42 Member 11998209 20-Sep-15 10:42
 Apriori Algorithm Member 1199820920-Sep-15 10:34 Member 11998209 20-Sep-15 10:34
 Efficient Data Mining Software Member 1051770411-Jul-15 2:21 Member 10517704 11-Jul-15 2:21
 request for your Aprori java code Member 1175977411-Jun-15 11:00 Member 11759774 11-Jun-15 11:00
 request for apriori code in php mau_lida6-Jun-15 0:23 mau_lida 6-Jun-15 0:23
 Last Visit: 31-Dec-99 18:00     Last Update: 25-Jul-21 0:43 Refresh 123456 Next ᐅ

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.