View source: R/association_rules.R
| association_rules | R Documentation |
Discovers association rules using the Apriori algorithm with proper
candidate pruning. Accepts netobject (extracts sequences as
transactions), data frames, lists, or binary matrices.
Support counting is vectorized via crossprod() for 2-itemsets
and logical matrix indexing for k-itemsets.
association_rules(
x,
min_support = 0.1,
min_confidence = 0.5,
min_lift = 1,
max_length = 5L
)
x |
Input data. Accepts:
|
min_support |
Numeric. Minimum support threshold. Default: 0.1. |
min_confidence |
Numeric. Minimum confidence threshold. Default: 0.5. |
min_lift |
Numeric. Minimum lift threshold. Default: 1.0. |
max_length |
Integer. Maximum itemset size. Default: 5. |
Uses level-wise Apriori (Agrawal & Srikant, 1994) with the full pruning step: after the join step generates k-candidates, all (k-1)-subsets are verified as frequent before support counting. This is critical for efficiency at k >= 4.
P(A and B). Fraction of transactions containing both antecedent and consequent.
P(B | A). Fraction of antecedent transactions that also contain the consequent.
P(A and B) / (P(A) * P(B)). Values > 1 indicate positive association; < 1 indicate negative association.
(1 - P(B)) / (1 - confidence). Measures departure from independence. Higher = stronger implication.
An object of class "net_association_rules" containing:
Data frame with columns: antecedent (list), consequent (list), support, confidence, lift, conviction, count, n_transactions.
List of frequent itemsets per level k.
Character vector of all items.
Integer.
Integer.
List of min_support, min_confidence, min_lift, max_length.
Agrawal, R. & Srikant, R. (1994). Fast algorithms for mining association rules. In Proc. 20th VLDB Conference, 487–499.
build_network, predict_links
# From a list of transactions
trans <- list(
c("plan", "discuss", "execute"),
c("plan", "research", "analyze"),
c("discuss", "execute", "reflect"),
c("plan", "discuss", "execute", "reflect"),
c("research", "analyze", "reflect")
)
rules <- association_rules(trans, min_support = 0.3, min_confidence = 0.5)
print(rules)
# From a netobject (sequences as transactions)
seqs <- data.frame(
V1 = sample(LETTERS[1:5], 50, TRUE),
V2 = sample(LETTERS[1:5], 50, TRUE),
V3 = sample(LETTERS[1:5], 50, TRUE)
)
net <- build_network(seqs, method = "relative")
rules <- association_rules(net, min_support = 0.1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.