Mine frequent itemsets, association rules or association hyperedges using the Apriori algorithm. The Apriori algorithm employs level-wise search for frequent itemsets. The implementation of Apriori used includes some improvements (e.g., a prefix tree and item sorting).

apriori(data, parameter = NULL, appearance = NULL, control = NULL)

## Arguments

data

object of class transactions or any data structure which can be coerced into transactions (e.g., a binary matrix or data.frame).

parameter

object of class APparameter or named list. The default behavior is to mine rules with minimum support of 0.1, minimum confidence of 0.8, maximum of 10 items (maxlen), and a maximal time for subset checking of 5 seconds (maxtime).

appearance

object of class APappearance or named list. With this argument item appearance can be restricted (implements rule templates). By default all items can appear unrestricted.

control

object of class APcontrol or named list. Controls the algorithmic performance of the mining algorithm (item sorting, report progress (verbose), etc.)

## Details

Calls the C implementation of the Apriori algorithm by Christian Borgelt for mining frequent itemsets, rules or hyperedges.

Note: Apriori only creates rules with one item in the RHS (Consequent)! The default value in APparameter for minlen is 1. This means that rules with only one item (i.e., an empty antecedent/LHS) like $$\{\} => \{beer\}$$ will be created. These rules mean that no matter what other items are involved, the item in the RHS will appear with the probability given by the rule's confidence (which equals the support). If you want to avoid these rules then use the argument parameter=list(minlen=2).

Notes on run time and memory usage: If the minimum support is chosen too low for the dataset, then the algorithm will try to create an extremely large set of itemsets/rules. This will result in very long run time and eventually the process will run out of memory. To prevent this, the default maximal length of itemsets/rules is restricted to 10 items (via the parameter element maxlen=10) and the time for checking subsets is limited to 5 seconds (via maxtime=5). The output will show if you hit these limits in the "checking subsets" line of the output. The time limit is only checked when the subset size increases, so it may run significantly longer than what you specify in maxtime. Setting maxtime=0 disables the time limit. Interrupting execution with Control-C/Esc is not recommended. Memory cleanup will be prevented resulting in a memory leak. Also, interrupts are only checked when the subset size increases, so it may take some time till the execution actually stops.

## Value

Returns an object of class rules or itemsets.

## References

R. Agrawal, T. Imielinski, and A. Swami (1993) Mining association rules between sets of items in large databases. In Proceedings of the ACM SIGMOD International Conference on Management of Data, pages 207--216, Washington D.C. Christian Borgelt and Rudolf Kruse (2002) Induction of Association Rules: Apriori Implementation. 15th Conference on Computational Statistics (COMPSTAT 2002, Berlin, Germany) Physica Verlag, Heidelberg, Germany.

Christian Borgelt (2003) Efficient Implementations of Apriori and Eclat. Workshop of Frequent Item Set Mining Implementations (FIMI 2003, Melbourne, FL, USA).

APRIORI Implementation: www.borgelt.net/apriori.html

APparameter-class, APcontrol-class, APappearance-class, transactions-class, itemsets-class, rules-class

## Examples

data("Adult")
## Mine association rules.
parameter = list(supp = 0.5, conf = 0.9, target = "rules"))#> Apriori
#>
#> Parameter specification:
#>  confidence minval smax arem  aval originalSupport maxtime support minlen
#>         0.9    0.1    1 none FALSE            TRUE       5     0.5      1
#>  maxlen target   ext
#>      10  rules FALSE
#>
#> Algorithmic control:
#>  filter tree heap memopt load sort verbose
#>     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
#>
#> Absolute minimum support count: 24421
#>
#> set item appearances ...[0 item(s)] done [0.00s].
#> set transactions ...[115 item(s), 48842 transaction(s)] done [0.03s].
#> sorting and recoding items ... [9 item(s)] done [0.00s].
#> creating transaction tree ... done [0.03s].
#> checking subsets of size 1 2 3 4 done [0.00s].
#> writing ... [52 rule(s)] done [0.00s].
#> creating S4 object  ... done [0.01s].summary(rules)#> set of 52 rules
#>
#> rule length distribution (lhs + rhs):sizes
#>  1  2  3  4
#>  2 13 24 13
#>
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
#>   1.000   2.000   3.000   2.923   3.250   4.000
#>
#> summary of quality measures:
#>     support         confidence          lift
#>  Min.   :0.5084   Min.   :0.9031   Min.   :0.9844
#>  1st Qu.:0.5415   1st Qu.:0.9155   1st Qu.:0.9937
#>  Median :0.5974   Median :0.9229   Median :0.9997
#>  Mean   :0.6436   Mean   :0.9308   Mean   :1.0036
#>  3rd Qu.:0.7426   3rd Qu.:0.9494   3rd Qu.:1.0057
#>  Max.   :0.9533   Max.   :0.9583   Max.   :1.0586
#>
#> mining info:
#>   data ntransactions support confidence
#>  Adult         48842     0.5        0.9