Apriori Association Analysis using R

install.packages("tidyverse")
library(tidyverse)

# install.packages("arules")
library(arules)
# install.packages("arulesViz")
library(arulesViz)

# prepare for transaction data

my_basket1 <- read.transactions("GroceryStore_Basket.csv", format="basket", sep=",")

my_sentiment <- 

my_basket1

inspect(my_basket1)

my_basket2 <- read.transactions("GroceryStore_Single.csv", format="single", sep=",", cols = c("TransactionID","Item"), header= TRUE)

inspect(my_basket2)

## (1) Import "Online Retail.csv" as a transaction data

summary(my_basket2)

itemFrequencyPlot(my_basket2)

rules <- apriori(my_basket2, parameter = list(supp=0.01, conf=0.8, maxlen =4))

summary(rules)
inspect(rules)

rules <- sort(rules, by = 'confidence', decreasing = TRUE)
inspect(rules[1:10])

itemFrequencyPlot(my_basket2)
## (2) Summarize and visualize transaction data 

rules <- apriori(my_basket2, parameter=list(supp=0.01, conf=0.8, maxlen=4, minlen=2))

summary(rules)
inspect(rules)

rules <- sort(rules, by = "confidence")

## (3) Apply the Apriori algorithm

## Remove redundant rules

is.redundant(rules)

inspect(rules[is.redundant(rules)])

rule2 <- rules[!is.redundant(rules)]
inspect(rules2)

plot(rules2)
plot(rules2, method = "graph")
plot(rules[1:10], method = "graph")


bread_rules <- apriori(my_basket2, parameter = list(supp=0.01, conf=0.8, maxlen=4), appearance=list(default="lhs", rhs = "BREAD"))

bread_rules <- sort(bread_rules, by = "confidence", decreasing = TRUE)
inspect(bread_rules)
plot(bread_rules, method="graph")

1 thought on “Apriori Association Analysis using R

  1. Pingback: Creating Twitter Sentiment Association Analysis using the Association Rules and Recommender System Methods – Data Flux

Leave a Reply