Assoication Rules

If you are someone who doesn't know about Association Rules, don't worry. You will get to know about it in a more easy way by reading this post. Association Rules Learning is also known as Association Rule Mining. It is simply finding association between attributes. For example, when  you buy something on an online store, it will prompt  as people who bought also bought this......
How do you think they give recommendations like this. The magic behind this is basically association rule mining.

In this post we are going to find association relationship between attributes. But please note that, the time taken for the analysis is considerably high. I was using an i3 machine with 4GB RAM, which ran out of memory most of the time. Therefore, I recommend you guys to use a more advanced machine.

 Following code find the association rules between the 11 attributes. This code will write generated a .CSV file of association rules.

#loading necessary libraries
library(arules)
library(arulesViz)

#copying country data frame into an variable
transaction_data <- sri_lanka_all

#columns need to converted to factors to change into transaction class
transaction_data[] <- lapply(transaction_data, factor)

#converting data fram into transactions
transaction_data <- as(transaction_data, "transactions")

#finding the most frequent items
#frequentItemSet <- eclat (transaction_data, parameter = list(supp = 0.07, maxlen = 11))

#creating assoication rules
rules <- apriori(transaction_data, parameter = list(supp = 0.001, conf = 0.5))

#sorting rules based on confidence
#rules_conf <- sort (rules, by="confidence", decreasing=TRUE)

#sorting rules based on lift
#rules_lift <- sort (rules, by="lift", decreasing=TRUE)

#finding redundant rules (subset rules of larger rules)
#redundant_rules <- which(colSums(is.subset(rules, rules)) > 1)

#Writing rules to a file

write(rules,file = "association_rules.csv",sep = ",",quote = TRUE,row.names = FALSE) 



You can get the source code here.





Comments

Popular posts from this blog

Getting Started with Data set

What is Cricket Sabermetrics?

What is this Blog about?