Apriori algorithm

from Wikipedia, the free encyclopedia

The Apriori algorithm is a method for association analysis , a field of data mining . It is used to find meaningful and useful relationships in transaction-based databases, which are represented in the form of so-called association rules. A frequent application of the a priori algorithm is the shopping basket analysis . Items are offered products and a purchase represents a transaction that contains the items purchased. The algorithm now determines correlations of the form:

When shampoo and aftershave were purchased, 90% of the time, shaving cream was also purchased .

A suitable database consists of a table of transactions (rows) in which any binary items (columns) are summarized. The a priori algorithm finds relationships between sets of items that occur in a large part of the transactions. The association rules that are output have the following form , there are and quantities of items and the rule states that if the item quantity occurs in a large part of the transactions , then the item quantity is also often included.

requirements

The a priori algorithm is used for databases of a certain form. The form of the database must be as follows:

  • is a lot of possible items
  • is the database consisting of transactions
  • a transaction combines a number of items

Typically, a set of more than 500,000 transactions is analyzed on a very large item basis. The database is displayed in a de-normalized database table, which has a column for each possible item. The lines contained each represent a transaction, with items contained in the transaction being marked with a 1, and items not contained with a 0. A transaction can therefore also be viewed as a vector with dimensions.

An association rule is of the form

where applies

, and

Evaluation of rules

Association rules are assessed using two probabilistic metrics: support and confidence. The apriori algorithm expects the values and , which represent the minimum support and the minimum confidence of a rule, so that they are taken into account.

Support

The support of a set of items is the probability that this set of items will occur in a transaction.

Be item set.

The support of an association rule , with and , is defined as

The support of a rule therefore indicates the relative frequency with which the rule occurs in the database. A high level of support is usually desirable in order to find statements about majorities.

Confidence

Be an association rule, with and .

The confidence of a rule corresponds to the probability of the conclusion under the condition of the premise:

so

Confidence measures the relative frequency of occurrence of the conclusion under the condition of the premise. A high value is also desirable for the confidence. Or to put it more simply: The confidence measures for what proportion of the transactions in which occurs, also occurs. To calculate the confidence, the number of all rule-compliant transactions (i.e. support) is divided by the number of transactions that contain.

The algorithm

The a priori algorithm receives as inputs

  • The database
  • The minimal support
  • The minimum confidence

and outputs a set of association rules that satisfy both and .

The algorithm works in two steps, both of which use a common step Apriori-Gen:

  1. Finding frequent quantities
  2. Creation of association rules

Finding more frequent item sets

The search for frequent item sets starts with 1-element sets and is continued iteratively with n-element sets until no item sets with sufficient support are found. In each iteration, a set of candidate sets is generated by means of the apriori gene and each set is checked for the property. If no new quantities can be found, the algorithm stops and outputs the quantities found.

  1. Calculate all 1-item Itemmengen with Support> : .
  2. For .
    1. Calculate amount of candidate out by means of a priori gene.
    2. Calculate the actual support from all amounts .
    3. Take the quantities with enough support in on.
    4. Is , break off.
  3. Give back.

The returned amount contains all common item amounts.

A priori gene

The sub-routine Apriori-Gen is used for the calculation of frequent quantities as well as for the generation of association rules. Instead of directly calculating the support for all possible item quantities, Apriori-Gen generates a number of candidates for further verification on the basis of frequently found quantities.

The routine receives as input a set of frequently- item sets ( ) and returns a set of -item sets ( ) as possible candidates. It is based on the principle that all subsets of a frequent item set are frequent, but all supersets of a non-frequent item set are also non-frequent. This avoids unnecessary support calculations.

  1. Generate item sets by merging two item sets that each have in common and add them . This step guarantees that only one element is added to the new set at a time.
  2. For each set in , check whether all subsets are included in. If not, remove it .

example

The input to Apriori-Gen is:

Step 1 of the a priori gene routine now calculates the following candidate set:

Step 2 removes the quantities and back off because and are not included in. So both sets are not frequent and your supersets don't need to be considered.

So the result of Apriori-Gen is

Generation of association rules

Only item sets that are inherently frequent have to be taken into account for this step of the algorithm. Such item sets were calculated by step 1 of the a priori algorithm. The Apriori-Gen routine used in step 1 is used again when generating association rules.

An attempt is made to generate association rules for each frequent item set found. It starts with the shortest possible (1-element) conclusions, which are iteratively enlarged. The following pseudocode is executed for each item set found :

  1. For each item set Z: calculate association rules of the form with and with .
  2. Generate with item sets each consisting of a found conclusion.
    1. Generate by Apriori gene.
    2. For each conclusion check from . If not, remove from .
    3. If , stop.
  3. Give back.

The generated rules satisfy all and .

literature

  • Rakesh Agrawal, Tomasz Imieliński, Arun Swami: Mining Association Rules between Sets of Items in Large Databases. In: Peter Buneman; Sushil Jajodia (Ed.): Proceedings of the 1993 ACM SIGMOD international conference on Management of data (= SIGMOD Record. Vol. 22, No. 2, June 1993). ACM, New York NY 1993, ISBN 0-89791-592-5 , pp. 207-216, doi : 10.1145 / 170035.170072
  • Rakesh Agrawal, Ramakrishnan Srikant: Fast Algorithms for Mining Association Rules. In: Jorge Bocca, Matthias Jarke , Carlo Zaniolo (eds.): Very large data bases. Proceedings of the 20th International Conference on Very Large Data Bases. Morgan Kaufmann Publishers Inc., Hove et al. 1994, ISBN 1-55860-153-8 , pp. 487-499, online (PDF; 282 kB) .
  • Jean-Marc Adamo: Data Mining for Association Rules and Sequential Patterns. Sequential and Parallel Algorithms . Springer, New York NY et al. 2001, ISBN 0-387-95048-6 (English).
  • Christoph Beierle, Gabriele Kern-Isberner: Methods of knowledge-based systems: fundamentals, algorithms, applications. , 4th edition. Vieweg + Teubner Verlag , 2008, p. 147ff. ISBN 3834805041

Web links