Preview:
# Apriori Algorithm in R

# Install and load required package
install.packages("arules")
library(arules)

# Load built-in transaction data
data("Groceries")

# Apply Apriori algorithm to find frequent itemsets
frequent_items <- apriori(Groceries, parameter = list(supp = 0.01, target = "frequent itemsets"))

# Generate association rules
rules <- apriori(Groceries, parameter = list(supp = 0.01, confidence = 0.5))

# Sort rules by lift
sorted_rules <- sort(rules, by = "lift", decreasing = TRUE)

# View top results
inspect(head(frequent_items, 10))
inspect(head(sorted_rules, 10))
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter