You are on page 1of 5

Association Rule

Association rule induction is a powerful method for so-called market basket analysis,
which aims at finding regularities in the shopping behavior of customers.
With the induction of association rules one tries to find sets of products that are
frequently bought together, so that from the presence of certain products in a shopping
cart one can infer (with a high probability) that certain other products are present.
An association rule is a rule like "If a customer buys wine and bread, he often buys
cheese, too."
An association rule states that if we pick a customer at random and find out that he
selected certain items (bought certain products, chose certain options etc.), we can be
confident, quantified by a percentage, that he also selected certain other items (bought
certain other products, chose certain other options etc.).

Example Usage
require 'apriori'
transactions = [ %w{beer doritos},
%w{apple cheese},
%w{beer doritos},
%w{apple cheese},
%w{apple cheese},
%w{apple doritos} ]
rules = Apriori.find_association_rules(transactions,
:min_items => 2,
:max_items => 5,
:min_support => 1,
:max_support => 100,
:min_confidence => 20)
puts rules.join("\n")
# Results:
# beer -> doritos (33.3/2, 100.0)
# doritos -> beer (50.0/3, 66.7)
# doritos -> apple (50.0/3, 33.3)
# apple -> doritos (66.7/4, 25.0)
# cheese -> apple (50.0/3, 100.0)
# apple -> cheese (66.7/4, 75.0)

# beer -> doritos (33.3/2, 100.0)
# means:
# * beer appears in 33.3% (2 total) of the transactions (the support)
# * beer implies doritos 100% of the time (the confidence)

Apriori Algorithm
Apriori is very much basic algorithm of Association rule mining. is used to mine
all frequent itemsets in database. The algorithm [2] makes many searches in database
to find frequent itemsets where kitemsets are used to generate k+1-itemsets. Each
k-itemset must be greater than or equal to minimum support threshold to be
frequency. Otherwise, it is called candidate itemsets. In the first, the algorithm scan
database to find frequency of 1-itemsets that contains only one item by
counting each item in database. The frequency of 1-itemsets is used to find
the itemsets in 2-itemsets which in turn is used to find 3-itemsets and so on until
there are not any more k-itemsets. If an itemset is not frequent, any large subset from
it is also non-frequent [1]; this condition prune from search space in database.

2) Description of the algorithm

Input: D, Database of transactions; min_sup, minimum
support threshold
Output: L, frequent itemsets in D
(1) L1=find_frequent_1-itemsets(D);
(2) for(k=2; Lk-1; k++){
(3) Ck=apriori_gen(Lk-1, min_sup);
(4) for each transaction tD{
(5) Ct=subset(Ck,t);
(6) for each candidate cCt
(7) c.count++
(8) }
(9) Lk={ cCk |c.countmin_sup }
(10) }

(11) return L=UkLk ;

Procedure apriori_gen(Lk-1:frequent(k-1)-itemsets)
(1) for each itemset l1 Lk-1{
(2) for each itemset l2 Lk-1{
(3) if(l1 [1]= l2 [1]) (l1 [2]= l2 [2]) (l1 [k-2]=
l2 [k-2]) (l1 [k-1]< l2 [k-1]) then {
(4) c=l1l2;
(5) if has_infrequent_subset(c, Lk-1) then
(6) delete c;
(7) else add c to Ck ;
(8) }}}
(9) return Ck;
Procedure has_infrequent_subset(c: candidate k-itemset;
(1) for each(k-1)-subset s of c {
(2) if s Lk-1 then
(3) return true; }
(4) return false;

Limitations of Apriori Algorithm

Apriori algorithm suffers from some weakness in spite of being clear and
simple. The main
limitation is costly wasting of time to hold a vastnumber of candidate sets with much
itemsets, low minimum support or large itemsets. For example, if there are 10
from frequent 1-itemsets, it need to generate more than 10
candidates into 2-length which in turn they will be
tested and accumulate [2]. Furthermore, to detect frequent pattern in size 100
(e.g.) v1, v2
v100, it have to generate 2
candidate itemsets [1] that yield on costly and wasting of time of
candidate generation. So, it will check for many sets from candidate itemsets, also it
will scan
database many times repeatedly for finding candidate itemsets. Apriori will be
very low and
inefficiency when memory capacity is limited with large number of transactions.
In this paper, we propose approach to reduce the time spent for searching in database
for frequent itemsets.

The Improved Algorithm of Apriori

This section will address the improved Apriori ideas, the improved Apriori, an
example of the
improved Apriori, the analysis and evaluation of the improved Apriori and the

The Improved Apriori ideas

The Improved Apriori
An Example of the Improved Apriori
The Analysis and Evaluation of the Improved Apriori