pkg <- 'arules' source("https://raw.githubusercontent.com/mhahsler/pkg_helpers/main/pkg_helpers.R") pkg_title(pkg)
The arules package family 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 the code of Christian Borgelt's popular and efficient C implementations of the association mining algorithms Apriori and Eclat. In addition, the following mining algorithms are available via fim4r:
Code examples can be found in Chapter 5 of the web book R Companion for Introduction to Data Mining.
pkg_citation(pkg, 2)
Additional mining algorithms
fim4r()
is provided in arules
.opus()
with format = 'itemsets'
. In-database analytics
Interface
Classification
Outlier Detection
Recommendation/Prediction
pkg_usage(pkg)
pkg_install(pkg)
Load package and mine some association rules.
library("arules") data("IncomeESL") trans <- transactions(IncomeESL) trans rules <- apriori(trans, supp = 0.1, conf = 0.9, target = "rules")
Inspect the rules with the highest lift.
inspect(head(rules, n = 3, by = "lift"))
arules
works seamlessly with tidyverse. For example:
dplyr
can be used for cleaning and preparing the transactions.transaction()
and other functions accept tibble
as input.|>
.ggplot2
.For example, we can remove the ethnic information column before creating transactions and then mine and inspect rules.
library("tidyverse") library("arules") data("IncomeESL") trans <- IncomeESL |> select(-`ethnic classification`) |> transactions() rules <- trans |> apriori(supp = 0.1, conf = 0.9, target = "rules", control = list(verbose = FALSE)) rules |> head(3, by = "lift") |> as("data.frame") |> tibble()
arules
and arulesViz
can now be used directly from Python with the Python
package arulespy
available form PyPI.
Please report bugs here on GitHub. Questions should be posted on stackoverflow and tagged with arules.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.