Learn R Programming

⚠️There's a newer version (1.7-8) of this package.Take me there.

arules — Mining Association Rules and Frequent Itemsets with R

The arules package for R provides the infrastructure for representing, manipulating and analyzing transaction data and patterns using frequent itemsets and association rules. The package also provides a wide range of interest measures and mining algorithms including a interfaces and the code of Christian Borgelt’s popular and efficient C implementations of the association mining algorithms Apriori and Eclat. Examples can be found in Chapter 5 of the web book R Companion for Introduction to Data Mining.

arules core packages:

  • arules: arules base package with data structures, mining algorithms (APRIORI and ECLAT), interest measures.
  • arulesViz: Visualization of association rules.
  • arulesCBA: Classification algorithms based on association rules (includes CBA).
  • arulesSequences: Mining frequent sequences (cSPADE).

Other related packages:

Additional mining algorithms

  • arulesNBMiner: Mining NB-frequent itemsets and NB-precise rules.
  • opusminer: OPUS Miner algorithm for filtered top-k association discovery.
  • RKEEL: Interface to KEEL’s association rule mining algorithm.
  • RSarules: Mining algorithm which randomly samples association rules with one pre-chosen item as the consequent from a transaction dataset.

In-database analytics

  • ibmdbR: IBM in-database analytics for R can calculate association rules from a database table.
  • rfml: Mine frequent itemsets or association rules using a MarkLogic server.

Interface

  • rattle: Provides a graphical user interface for association rule mining.
  • pmml: Generates PMML (predictive model markup language) for association rules.

Classification

  • arc: Alternative CBA implementation.
  • inTrees: Interpret Tree Ensembles provides functions for: extracting, measuring and pruning rules; selecting a compact rule set; summarizing rules into a learner.
  • rCBA: Alternative CBA implementation.
  • qCBA: Quantitative Classification by Association Rules.
  • sblr: Scalable Bayesian rule lists algorithm for classification.

Outlier Detection

Recommendation/Prediction

  • recommenerlab: Supports creating predictions using association rules.

Installation

Stable CRAN version: install from within R with

install.packages("arules")

Current development version: install from GitHub (needs devtools and Rtools for Windows).

devtools::install_github("mhahsler/arules")

Usage

Load package and mine some association rules.

library("arules")
data("IncomeESL")

trans <- transactions(IncomeESL)
trans
## transactions in sparse format with
##  8993 transactions (rows) and
##  84 items (columns)
rules <- apriori(trans, parameter = list(supp = 0.1, 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.1      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 899 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[84 item(s), 8993 transaction(s)] done [0.01s].
## sorting and recoding items ... [42 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.03s].
## writing ... [457 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].

Inspect the rules with the highest lift.

inspect(head(rules, n = 3, by = "lift"))
##     lhs                           rhs                      support confidence coverage lift count
## [1] {dual incomes=no,                                                                            
##      householder status=own}   => {marital status=married}    0.10       0.97     0.10  2.6   914
## [2] {years in bay area=>10,                                                                      
##      dual incomes=yes,                                                                           
##      type of home=house}       => {marital status=married}    0.10       0.96     0.10  2.6   902
## [3] {dual incomes=yes,                                                                           
##      householder status=own,                                                                     
##      type of home=house,                                                                         
##      language in home=english} => {marital status=married}    0.11       0.96     0.11  2.6   988

Using arule and tidyverse

arules works seamlessly with tidyverse. For example, dplyr can be used for cleaning and preparing the transactions and then functions in arules can be used with %>%.

library("tidyverse")
library("arules")
data("IncomeESL")

trans <- IncomeESL %>% transactions()

rules <- trans %>% apriori(parameter = list(supp = 0.1, 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.1      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 899 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[84 item(s), 8993 transaction(s)] done [0.01s].
## sorting and recoding items ... [42 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.03s].
## writing ... [457 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
rules %>% head(n = 3, by = "lift") %>% inspect()
##     lhs                           rhs                      support confidence coverage lift count
## [1] {dual incomes=no,                                                                            
##      householder status=own}   => {marital status=married}    0.10       0.97     0.10  2.6   914
## [2] {years in bay area=>10,                                                                      
##      dual incomes=yes,                                                                           
##      type of home=house}       => {marital status=married}    0.10       0.96     0.10  2.6   902
## [3] {dual incomes=yes,                                                                           
##      householder status=own,                                                                     
##      type of home=house,                                                                         
##      language in home=english} => {marital status=married}    0.11       0.96     0.11  2.6   988

Using arules from Python

See Getting started with arules using Python.

Support

Please report bugs here on GitHub. Questions should be posted on stackoverflow and tagged with arules.

References

Copy Link

Version

Install

install.packages('arules')

Monthly Downloads

35,570

Version

1.7-2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

December 10th, 2021

Functions in arules (1.7-2)

Groceries

Groceries Data Set
APappearance-class

Class APappearance --- Specifying the appearance Argument of Apriori to Implement Rule Templates
Adult

Adult Data Set
AScontrol-classes

Classes AScontrol, APcontrol, ECcontrol --- Specifying the control Argument of apriori() and eclat()
DATAFRAME

Data.frame Representation for arules Objects
Mushroom

Mushroom Data Set
Income

Income Data Set
ASparameter-classes

Classes ASparameter, APparameter, ECparameter --- Specifying the parameter Argument of apriori() and eclat()
LIST

List Representation for Objects Based on Class itemMatrix
Epub

Epub Data Set
apriori

Mining Associations with Apriori
combine

Combining Objects
hierarchy

Support for Item Hierarchies
affinity

Computing Affinity Between Items
associations-class

Class associations - A Set of Associations
confint

Confidence Intervals for Association Interest Measures
eclat

Mining Associations with Eclat
duplicated

Find Duplicated Elements
interestMeasure

Calculate Additional Interest Measures
hits

Computing Transaction Weights With HITS
SunBai

The SunBai Data Set
[-methods

Methods for "[": Extraction or Subsetting in Package 'arules'
inspect

Display Associations and Transactions in Readable Form
discretize

Convert a Continuous Variable into a Categorical Variable
image

Visual Inspection of Binary Incidence Matrices
coverage

Calculate coverage for rules
dissimilarity

Dissimilarity Matrix Computation for Associations and Transactions
itemFrequency

Getting Frequency/Support for Single Items
itemCoding

Item Coding --- Conversion between Item Labels and Column IDs
read.transactions

Read Transaction Data
ruleInduction

Rule Induction from Itemsets
addComplement

Add Complement-items to Transactions
is.significant

Find Significant Rules
abbreviate

Abbreviate function for item labels in transactions, itemMatrix and associations
is.superset

Find Super and Subsets
itemFrequencyPlot

Creating a Item Frequencies/Support Bar Plot
is.generator

Find Generator Itemsets
itemMatrix-class

Class itemMatrix --- Sparse Binary Incidence Matrix to Represent Sets of Items
read.PMML

Read and Write PMML
predict

Model Predictions
rules-class

Class rules --- A Set of Rules
is.closed

Find Closed Itemsets
subset

Subsetting Itemsets, Rules and Transactions
match

Value Matching
merge

Adding Items to Data
sample

Random Samples and Permutations
itemSetOperations

Itemwise Set Operations
setOperations

Set Operations
unique

Remove Duplicated Elements from a Collection
transactions-class

Class transactions --- Binary Incidence Matrix for Transactions
support

Support Counting for Itemsets
is.maximal

Find Maximal Itemsets
is.redundant

Find Redundant Rules
itemsets-class

Class itemsets --- A Set of Itemsets
length

Getting the Number of Elements
crossTable

Cross-tabulate joint occurrences across pairs of items
proximity-classes

Classes dist, ar\_cross\_dissimilarity and ar\_similarity --- Proximity Matrices
sort

Sort Associations
size

Number of Items
weclat

Mining Associations from Weighted Transaction Data with Eclat (WARM)
supportingTransactions

Supporting Transactions
random.transactions

Simulate a Random Transaction Data Set
tidLists-class

Class tidLists --- Transaction ID Lists for Items/Itemsets
write

Write Transactions or Associations to a File