# install.packages("arules")
# install.packages("arulesViz")
package 'arules' successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\RtmpEXWcKI\downloaded_packages
also installing the dependencies 'mclust', 'flexmix', 'prabclus', 'diptest', 'trimcluster', 'gridExtra', 'fpc', 'viridis', 'TSP', 'qap', 'gclus', 'dendextend', 'registry', 'irlba', 'crosstalk', 'scatterplot3d', 'seriation', 'igraph', 'DT', 'plotly'
package 'mclust' successfully unpacked and MD5 sums checked package 'flexmix' successfully unpacked and MD5 sums checked package 'prabclus' successfully unpacked and MD5 sums checked package 'diptest' successfully unpacked and MD5 sums checked package 'trimcluster' successfully unpacked and MD5 sums checked package 'gridExtra' successfully unpacked and MD5 sums checked package 'fpc' successfully unpacked and MD5 sums checked package 'viridis' successfully unpacked and MD5 sums checked package 'TSP' successfully unpacked and MD5 sums checked package 'qap' successfully unpacked and MD5 sums checked package 'gclus' successfully unpacked and MD5 sums checked package 'dendextend' successfully unpacked and MD5 sums checked package 'registry' successfully unpacked and MD5 sums checked package 'irlba' successfully unpacked and MD5 sums checked package 'crosstalk' successfully unpacked and MD5 sums checked package 'scatterplot3d' successfully unpacked and MD5 sums checked package 'seriation' successfully unpacked and MD5 sums checked package 'igraph' successfully unpacked and MD5 sums checked package 'DT' successfully unpacked and MD5 sums checked package 'plotly' successfully unpacked and MD5 sums checked package 'arulesViz' successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\RtmpEXWcKI\downloaded_packages
library(arules)
library(arulesViz)
# library(datasets)
Loading required package: Matrix Attaching package: 'arules' The following objects are masked from 'package:base': abbreviate, write Loading required package: grid
# w1 = read.table("C:/Users/sbgowtham/Desktop/comm.csv")
w1 = read.table("data//retail.csv")
# trans = read.transactions("C:/Users/sbgowtham/Desktop/comm.csv", format = "basket", sep=",");
trans = read.transactions("data//retail.csv", format = "basket", sep=",");
itemFrequencyPlot(trans,topN=20,type="absolute")
rules<-apriori(data=trans, parameter=list(supp=0.001,conf = 0.08),
appearance = list(default="lhs",rhs="mobile"),control = list(verbose=F))
rules<-sort(rules, decreasing=TRUE,by="confidence")
inspect(rules[1:10])
plot(rules,method="graph",interactive=TRUE,shading=NA)
lhs rhs support confidence lift [1] {laptop} => {mobile} 0.125 1.0000000 1.6000000 [2] {headset,laptop} => {mobile} 0.125 1.0000000 1.6000000 [3] {charger,pad} => {mobile} 0.125 1.0000000 1.6000000 [4] {charger,headset,pad} => {mobile} 0.125 1.0000000 1.6000000 [5] {charger} => {mobile} 0.250 0.6666667 1.0666667 [6] {pad} => {mobile} 0.250 0.6666667 1.0666667 [7] {headset,pad} => {mobile} 0.250 0.6666667 1.0666667 [8] {} => {mobile} 0.625 0.6250000 1.0000000 [9] {headset} => {mobile} 0.500 0.5714286 0.9142857 [10] {charger,headset} => {mobile} 0.125 0.5000000 0.8000000
Market Basket Analysis is for the retailers to identify relationships between the items that people buy.
Association Rules is widely used to analyze retail basket or transaction data
An Example of Association Rules Assume there are 100 customers 10 out of them bought milk, 8 bought butter and 6 bought both of them.
bought milk => bought butter
Support = P(Milk & Butter) = 6/100 = 0.06
confidence = support/P(Butter) = 0.06/0.08 = 0.75
lift = confidence/P(Milk) = 0.75/0.10 = 7.5
Online Retail dataset from UCI Machine Learning repository's
http://archive.ics.uci.edu/ml/datasets/online+retail