pkg <- 'arules'

source("https://raw.githubusercontent.com/mhahsler/pkg_helpers/main/pkg_helpers.R")
pkg_title(pkg)

Anaconda.org

Introduction

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)

Packages

arules core packages

Other related packages

Additional mining algorithms

In-database analytics

Interface

Classification

Outlier Detection

Recommendation/Prediction

pkg_usage(pkg)
pkg_install(pkg)

Usage

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"))

Using arules with tidyverse

arules works seamlessly with tidyverse. For example:

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()

Using arules from Python

arules and arulesViz can now be used directly from Python with the Python package arulespy available form PyPI.

Support

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

References



mhahsler/arules documentation built on March 19, 2024, 5:45 p.m.