## cluster items in Groceries with support > 5\%
data("Groceries")
s <- Groceries[,itemFrequency(Groceries)>0.05]
d_jaccard <- dissimilarity(s, which = "items")
plot(hclust(d_jaccard, method = "ward"))
## cluster transactions for a sample of Adult
data("Adult")
s <- sample(Adult, 200)
## calculate Jaccard distances and do hclust
d_jaccard <- dissimilarity(s)
plot(hclust(d_jaccard))
## calculate affinity-based distances and do hclust
d_affinity <- dissimilarity(s, method = "affinity")
plot(hclust(d_affinity))
## cluster rules
rules <- apriori(Adult, parameter=list(support=0.3))
rules <- subset(rules, subset = lift > 2)
## use affinity
## we need to supply the item affinities from the dataset (sample)
d_affinity <- dissimilarity(rules, method = "affinity",
args = list(affinity = affinity(s)))
plot(hclust(d_affinity))
## use gupta
d_gupta <- dissimilarity(rules, method = "gupta", args=list(trans=Adult))
plot(hclust(d_gupta))
Run the code above in your browser using DataLab