Posts

Showing posts from November, 2018

Association Rule Mining using Arules in R

Let's consider a dataset. The dataset has to be in a certain format ..txn format..if its not there arules doesn't work. We take  a csv file and then convert it to transaction in example below. Let's create dataset CustomerId,Products 100, Savings Pre 100,Home20 101,Home20 102,Checking Zero 102,Home20 102,Gold10 103,Home20 103,Gold20 104,Checking Zero 104,Savings Pre 104,Home20 ArulesUsage.R ------------ ds<-read.csv("ProductsSmall.csv") colnames(ds) library(arules) trans<-as(split(ds[,"Products"],ds[,"CustomerId"]),"transactions") summary(trans) # Lists the most frequent items too... rules<-apriori(trans,parameter = list(support = 0.14,                  confidence = 0.05,                  minlen = 2)) inspect(rules) rules<-sort(rules,by="lift") rules_output<-rules[!is.redundant(rules)] inspect(rules_output) library(pmml) saveXML(pmml(rules_output),"Apriori_ProductsSmall.p