Sei sulla pagina 1di 23

BUSINESS ANALYTICS

ASSIGNMENT -2

MARKET BASKET ANALYSIS

Submitted By,

Laavanyaa P R

17MB24

MBAPT-Final year
Association rule mining

OBJECTIVE

To perform the association rule mining and generate rules for the dataset

INSTALLATION OF REQUIRED PACKAGES AND LIBRARY

Source File:
#To install required packages
install.packages("arules")
install.packages("arulesViz")
install.packages("tidyverse")
install.packages("plyr")
install.packages("ggplot2")
install.packages("knitr")
install.packages("lubridate")
#Has apriori algorithm
library(arules)
#Visualizing the rules
library(arulesViz)
#The tidyverse is an opinionated collection of R packages designed for data science
library(tidyverse)
#Tools for Splitting, Applying and Combining Data
library(dplyr)
#Create graphics and charts
library(ggplot2)
#Dynamic Report generation in R
library(knitr)
#Lubridate is an R package that makes it easier to work with dates and times.
library(lubridate)
#to read excel data file
library(readxl)

Console File:

The required packages will be installed


LOAD THE DATA SET

Source file:
#To incorporate excel data file
Marketbasket<-read.csv(file.choose(),header = TRUE)

Console file:

> library(readxl)
> Marketbasket<-read.csv(file.choose(),header = TRUE)

VIEW AND PROVIDE SUMMARY OF THE DATA SET

Source file:
#to view the data
View(Marketbasket)
#To view the structureof the data set
str(Marketbasket)

Console file:
> #to view the data
> View(basket)
> #To view the structureof the data set
> str(basket)
'data.frame': 3867 obs. of 13 variables:
$ Store_ID : int 1 1 1 1 1 1 1 1 1 1 ...
$ Invoice_No: int 100012 100012 100012 100012 100017 100017
100018 100018 100018 100018 ...
$ Till_No : int 1 1 1 1 1 1 1 1 1 1 ...
$ Item_No : int 1 2 3 4 1 2 1 2 3 4 ...
$ Txn_Date : Factor w/ 1 level "1-Jan-16": 1 1 1 1 1 1 1 1 1 1
...
$ SKU_Code : Factor w/ 301 levels "SKU001","SKU002",..: 32 76
208 48 4 283 32 37 38 39 ...
$ Item_Desc : Factor w/ 301 levels "Aerated Drinks",..: 33 80
205 51 5 279 33 39 40 41 ...
$ Qty : num 0.25 0.5 1 0.25 0.25 1 0.25 12 0.25 0.25 ...
$ Unit : Factor w/ 5 levels "Can","Kg","Litre",..: 2 3 4 2
2 4 2 5 2 2 ...
$ Unit_Price: int 55 67 55 67 220 33 55 10 300 650 ...
$ Price : num 13.8 33.5 55 16.8 55 ...
$ Cust_ID : int 23464 23464 23464 23464 23469 23469 23470
23470 23470 23470 ...
$ Emp_ID : Factor w/ 9 levels "EMP001","EMP002",..: 1 1 1 1
1 1 1 1 1 1 ...

CONVERTING THE DATASET INTO TRANSACTIONAL DATA

Source file:

Marketbasket1<-split(Marketbasket_1_$Item_Desc,Marketbasket_1_$Invoice_No)
View(Marketbasket1)
Marketbasket2=as(Marketbasket1,"transactions")
Inspect(Marketbasket2)

Console file:

[281] {Body Lotion,


Boiled Rice,
Books,
Bottle Opener,
Bottom wear} 100421
[282] {Crockery,
Cup & Saucer,
Cut Vegetables,
Dahi,
Desserts,
Detergents} 100422
[283] {Agarbatties} 100424
[284] {Cereals,
Cut Vegetables,
Dahi,
Fruit Juices,
Garlic,
Groundnut Oil,
Soaps} 100425
[285] {Agarbatties} 100426
[286] {Panties,
Papads,
Papaya} 100427
[287] {Paper Napkins,
Pasta,
Pastas,
PASTRIES,
PeanutButter,
Peanuts,
Pegs,
Pen,
Pencil Case,
Pencils,
Pepsi,
Peripheral,
Photo Frames,
Pickles & Olives,
Pillow Covers,
Plain Biscuits,
Plain Dahi,
Plants,
Plastic Bag,
Platters,
Plugs / Sockers,
Poha,
Pomogranate,
Pork,
Potato,
Potato Chips,
Premium Cakes,
Pressure Cooker,
Pulses} 100429
[288] {Bandage} 100431
[289] {Canned Food,
Canned Fruits,
Milk,
Onion,
Punches,
Puzzle Games,
Raw Chicken,
Raw Rice,
Razors,
Ready to Eat Food,
Regular,
Regular Eggs,
Remote Controlled Games} 100432
[290] {Agarbatties,
Brinjal,
Cereals,
Eggs,
Mosquito Repellant,
Soaps,
Wheat} 100433
[291] {Cut Vegetables,
Dahi,
Fruit Juices,
Groundnut Oil,
Hair Oil,
Masalas,
Milk,
Noodles,
Onion,
Other Cereals,
Other Dals,
Other Flours,
Others,
Soaps} 100434
[292] {Potato} 100435
[293] {Brinjal,
Cawliflower,
Cereals,
Cut Vegetables,
Rawa Sooji} 100436
[294] {Bowls,
Boys Swimsuit,
Branded Cakes,
Bread,
Breakfast Cereals,
Masalas,
Mosquito Repellant,
Noodles} 100437
[295] {Dahi,
Fruit Juices,
Garlic} 100438
[296] {Dinner Set,
Disposable Ware,
Eggs,
Exercise Accessories,
Face Care,
Face Packs} 100439
[297] {Facial Tissues,
Fairness Whitening,
Fasteners,
Files} 100440
[298] {Flavoured Cookies,
Foils} 100441
[299] {Food,
Footballs,
Fresh Water,
Fridge Bottles,
Frozen Chicken,
Frozen Fish,
Frozen Parathas,
Frozen Peas,
Frozen Pizzas,
Frozen Pork,
Frozen Starters,
Frozen Vegetables,
Fruit Juices,
Fruit Salads,
Frying Pan,
Games,
Garlic,
Ghee,
Gift Vouchers,
Gourds,
Grater} 100442
[300] {Gravy Mixes/Paste,
Ground Coffee,
Groundnut Oil,
Hair Care,
Hair Creams,
Hair Dye,
Hair Gel,
Hair Oil,
Hand Bags,
Hand Sanitizers,
Milk} 100443
[301] {Bread,
Butter,
Flavoured Cookies,
Juices,
Potato Chips} 100445
[302] {Masalas,
Noodles,
Other Dals,
Other Flours,
Others,
Raw Mutton,
Salt,
Soaps} 100447
[303] {Bread,
Breakfast Cereals,
Flavoured Cookies,
Juices,
Potato Chips} 100448
[304] {Bandage,
Bread,
Butter} 100449
[305] {Fruit Juices,
Noodles,
Onion,
Potato Chips} 100450
[306] {Hand Blender,
Hand Towel,
Hand Wash,
Handicrafts,
Hangers} 100451
[307] {Potato,
Potato Chips,
Pulses} 100452
[308] {Bread,
Butter,
Rawa Sooji} 100453
[309] {Raw Chicken,
Raw Mutton,
Raw Rice,
Rawa Sooji} 100454

str(Marketbasket2)
Formal class 'transactions' [package "arules"] with 3 slots
..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
.. .. ..@ i : int [1:3477] 211 257 258 259 260 266 273 184 31 126 ...
.. .. ..@ p : int [1:416] 0 7 8 11 20 25 26 36 40 72 ...
.. .. ..@ Dim : int [1:2] 301 415
.. .. ..@ Dimnames:List of 2
.. .. .. ..$ : NULL
.. .. .. ..$ : NULL
.. .. ..@ factors : list()
..@ itemInfo :'data.frame': 301 obs. of 1 variable:
.. ..$ labels: chr [1:301] "Aerated Drinks" "Agarbatties" "Antiseptic
Liquid" "Appalams" ...
..@ itemsetInfo:'data.frame': 415 obs. of 1 variable:
.. ..$ transactionID: chr [1:415] "100001" "100004" "100005" "100006" ...

APPLYING GR_RULES

Source file:

gr_rules<-apriori(Marketbasket2)

Console file:

> gr_rules<-apriori(Marketbasket2)
Apriori

Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen maxlen target
0.8 0.1 1 none FALSE TRUE 5 0.1 1 10 rules FA

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
Absolute minimum support count: 41
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [18 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [4 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].

Inference

R takes the default value of support as 0.1 which means the number of cutomers & confidence
as 0.8 which is the probability as 80% , On applying the gr_rules and apiori 4 Rules have been
generated

Source file:

gr_rules<-apriori(Marketbasket2,parameter = list(supp=0.055,conf=0.8))

Console file:

> gr_rules<-apriori(Marketbasket2,parameter = list(supp=0.055,conf=0.8))


Apriori

Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen
maxlen target ext
0.8 0.1 1 none FALSE TRUE 5 0.055 1
10 rules FALSE

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE

Absolute minimum support count: 22

set item appearances ...[0 item(s)] done [0.00s].


set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [43 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 5 done [0.00s].
writing ... [210 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].

Inference
R takes the default value of support as 0.055 which means the number of cutomers &
confidence as 0.8 which is the probability as 80% , On applying the gr_rules and apiori 210
Rules have been generated
Source file:

#Inspecting the rules

inspect(gr_rules[1:5])

Console file:

> inspect(gr_rules[1:5])

lhs rhs support confidence lift count


[1] {Butter} => {Bread} 0.10361446 0.8431373 3.887800 43
[2] {Banana} => {Apple} 0.05542169 0.9200000 6.060317 23
[3] {Other Cereals} => {Others} 0.06024096 0.8620690 10.522312 25
[4] {Other Cereals} => {Other Flours} 0.06024096 0.8620690 10.221675 25
[5] {Other Cereals} => {Other Dals} 0.06987952 1.0000000 10.641026 29

Inference

Top 5 items in the marketbasket is retrived

Source file:

#to sort it to decreasing order of support

gr_rules<-sort(gr_rules,by="support",decreasing = T)

inspect(gr_rules[1:10])

Console file:

> inspect(gr_rules[1:10])
lhs rhs support confidence lift count
[1] {Dahi} => {Cut Vegetables} 0.11807229 0.9800000 6.893220 49
[2] {Cut Vegetables} => {Dahi} 0.11807229 0.8305085 6.893220 49
[3] {Breakfast Cereals} => {Bread} 0.10602410 0.8148148 3.757202 44
[4] {Butter} => {Bread} 0.10361446 0.8431373 3.887800 43
[5] {Raw Mutton} => {Raw Chicken} 0.09397590 0.8666667 6.660494 39
[6] {Cereals,Dahi} => {Cut Vegetables} 0.09156627 1.0000000 7.033898 38
[7] {Cereals,Cut Vegetables} => {Dahi} 0.09156627 0.9743590 8.087179 38
[8] {Dahi,Fruit Juices} => {Cut Vegetables} 0.08674699 0.9729730 6.843793 36
[9] {Cut Vegetables,Fruit Juices} => {Dahi} 0.08674699 0.8181818 6.790909 36
[10] {Cawliflower} => {Cereals} 0.08192771 0.8095238 6.587302 34
Inference

Top 10 items in the marketbasket is retrived based on largest to smallest sorting order with respect to
support and count

Source file:

#To remove redundant rules

redundant_rules<-is.redundant(gr_rules)

redundant_rules

Console file:

redundant_rules<-is.redundant(gr_rules)
> redundant_rules
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[20] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
[39] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[58] FALSE FALSE TRUE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[77] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE
[96] TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
[115] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[134] TRUE TRUE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE
[153] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE
[172] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
[191] TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE
[210] TRUE

Inference

To remove the repeated items .Some of the rules might have repeated, inorder to ignore the repeated rules
we are checking using redundant rules.

Source file:

#To know the count of redundant rules

summary(redundant_rules)
Console file:

> summary(redundant_rules)
Mode FALSE TRUE
logical 136 74

Inference

To know the exact count of false and true rules

Source file:

#To remove redundant rules

gr_rules<-gr_rules[!redundant_rules]

Console file:

> gr_rules<-gr_rules[!redundant_rules]
> inspect(gr_rules[1:5])
lhs rhs support confidence lift count
[1] {Dahi} => {Cut Vegetables} 0.1180723 0.9800000 6.893220 49
[2] {Cut Vegetables} => {Dahi} 0.1180723 0.8305085 6.893220 49
[3] {Breakfast Cereals} => {Bread} 0.1060241 0.8148148 3.757202 44
[4] {Butter} => {Bread} 0.1036145 0.8431373 3.887800 43
[5] {Raw Mutton} => {Raw Chicken} 0.0939759 0.8666667 6.660494 39

Inference

To display after removing the redundant values

Source file:

#To display summary of rules after removing redundancy

summary(gr_rules)

Console file:

> summary(gr_rules)
set of 136 rules
rule length distribution (lhs + rhs):sizes
2 3 4
33 96 7

Min. 1st Qu. Median Mean 3rd Qu. Max.


2.000 3.000 3.000 2.809 3.000 4.000

summary of quality measures:


support confidence lift count
Min. :0.05542 Min. :0.8000 Min. : 3.757 Min. :23.00
1st Qu.:0.05783 1st Qu.:0.8504 1st Qu.: 6.640 1st Qu.:24.00
Median :0.06265 Median :0.9062 Median : 8.078 Median :26.00
Mean :0.06568 Mean :0.9061 Mean : 8.398 Mean :27.26
3rd Qu.:0.06988 3rd Qu.:0.9630 3rd Qu.:10.489 3rd Qu.:29.00
Max. :0.11807 Max. :1.0000 Max. :12.206 Max. :49.00

mining info:
data ntransactions support confidence
Marketbasket2 415 0.055 0.8

Inference

The summary of data is displayed

Sales case of Magazines with Support 0.001 and Confidence 0.5

Source file:

gr_rules_Magazines<-apriori(Marketbasket2,parameter = list(supp=0.001,conf=0.5),
appearance = list(default="rhs",lhs="Magazines"))

plot(gr_rules_Magazines,method="graph")
plot(gr_rules_Magazines,method="graph",engine='interactive')
inspect(gr_rules_Magazines[1:10])

Console file:
> gr_rules_Magazines<-apriori(Marketbasket2,parameter =
list(supp=0.001,conf=0.5),
+ appearance = list(default="rhs",lhs="Magazines"))
Apriori

Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen
maxlen target ext
0.5 0.1 1 none FALSE TRUE 5 0.001 1
10 rules FALSE

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE

Absolute minimum support count: 0

set item appearances ...[1 item(s)] done [0.00s].


set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [301 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [29 rule(s)] done [0.00s].
creating S4 object ... done [0.00s]

> inspect(gr_rules_Magazines[1:10])
lhs rhs support confidence lift count
[1] {Magazines} => {Laundry Bag} 0.007228916 0.6 49.8 3
[2] {Magazines} => {Lassi} 0.007228916 0.6 49.8 3
[3] {Magazines} => {Ladies TShirts} 0.007228916 0.6 49.8 3
[4] {Magazines} => {Ladies Tops} 0.007228916 0.6 49.8 3
[5] {Magazines} => {Ladies Socks} 0.007228916 0.6 49.8 3
[6] {Magazines} => {Ladies Sleepers} 0.007228916 0.6 49.8 3
[7] {Magazines} => {Kitchenware} 0.007228916 0.6 49.8 3
[8] {Magazines} => {Kids Wear} 0.007228916 0.6 49.8 3
[9] {Magazines} => {Marinated Mutton} 0.007228916 0.6 49.8 3
[10] {Magazines} => {Knife} 0.007228916 0.6 49.8 3
Inference

No of Rules: 29
Support: 0.007
Confidence: 0.6
Lift: 49.8
Inference: 60% of probability that 0.7% of total no of customers buys both
Magazines with lipcare,living room accessories and Pyjama.Lift is greater than 1,henceforth
this sales case denotes complementary effect(i.e.,) People who buys Magazines also
buy all these products.So we can either give price bundling (combo packs) and
place them nearer or we can place it in a little distance,so people who buys
Magazines might buy some other product while searching for lipcare,living room accessories and Pyjama.

Sales case of Marinated chicken with Support 0.001 and Confidence 0.8

Source file:

gr_rules_MarinatedChicken<-apriori(Marketbasket2,parameter = list(supp=0.001,conf=0.8),appearance =
list(default="rhs",lhs="Marinated Chicken"))

plot(gr_rules_MarinatedChicken,method="graph")
plot(gr_rules_MarinatedChicken,method="graph",engine='interactive')
inspect(gr_rules_MarinatedChicken[1:10])
Console file:

> gr_rules_MarinatedChicken<-apriori(Marketbasket2,parameter = list(supp=0.001,conf=0.8),appearance = list(default="rhs",lhs="Marinated Chicken


Apriori

Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext
0.8 0.1 1 none FALSE TRUE 5 0.001 1 10 rules FALSE

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE

Absolute minimum support count: 0

set item appearances ...[1 item(s)] done [0.00s].


set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [301 item(s)] done [0.01s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [9 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].
> plot(gr_rules_MarinatedChicken,method="graph")
> plot(gr_rules_MarinatedChicken,method="graph",engine='interactive')

inspect(gr_rules_MarinatedChicken[1:5])
lhs rhs support confidence lift count
[1] {Marinated Chicken} => {Marinated Mutton} 0.009638554 0.8 66.4 4
[2] {Marinated Chicken} => {Margarines} 0.012048193 1.0 83.0 5
[3] {Marinated Chicken} => {Mens Pyjama} 0.009638554 0.8 66.4 4
[4] {Marinated Chicken} => {Ladies Pyjama} 0.009638554 0.8 66.4 4
[5] {Marinated Chicken} => {Mangoes} 0.009638554 0.8 66.4 4
Inference

No of Rules: 9
Support: 0.009
Confidence: 0.8
Lift: 83.0
Inference: 80% of probability that 0.9% of total no of customers buys both
Marinated Chicken with Marinated Mutton, Margarines,Mangoes.Lift is greater than 1,henceforth
this sales case denotes complementary effect(i.e.,) People who buys Marinated Chicken also
buy all these products.All the non veg products can be kept aside.Maida and margaraine type of items can
be placed near

Sales case Noodles with Support 0.01 and Confidence 0.2

Source file:

gr_rules_Noodles<-apriori(Marketbasket2,parameter = list(supp=0.01,conf=0.2),appearance =
list(default="rhs",lhs="Noodles"))

plot(gr_rules_ Noodles,method="graph")
plot(gr_rules_ Noodles,method="graph",engine='interactive')
inspect(gr_rules_ Noodles [1:10])
Console file:

> gr_rules_Noodles<-apriori(Marketbasket2,parameter =
list(supp=0.01,conf=0.2),appearance = list(default="rhs",lhs="Noodles"))
Apriori

Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen
maxlen target ext
0.2 0.1 1 none FALSE TRUE 5 0.01 1
10 rules FALSE

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE

Absolute minimum support count: 4

set item appearances ...[1 item(s)] done [0.00s].


set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [282 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [25 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].
> plot(gr_rules_Noodles,method="graph")
> plot(gr_rules_ Noodles,method="graph",engine='interactive')
> inspect(gr_rules_Noodles [1:10])
lhs rhs support confidence lift count
[1] {} => {Bread} 0.21686747 0.2168675 1.000000 90
[2] {Noodles} => {Hair Oil} 0.03373494 0.2258065 4.259531 14
[3] {Noodles} => {Other Cereals} 0.05060241 0.3387097 4.847052 21
[4] {Noodles} => {Garlic} 0.03373494 0.2258065 3.231368 14
[5] {Noodles} => {Groundnut Oil} 0.04578313 0.3064516 3.437228 19
[6] {Noodles} => {Potato} 0.04337349 0.2903226 3.442396 18
[7] {Noodles} => {Rawa Sooji} 0.03132530 0.2096774 1.359627 13
[8] {Noodles} => {Pulses} 0.03855422 0.2580645 3.059908 16
[9] {Noodles} => {Raw Mutton} 0.04337349 0.2903226 2.677419 18
[10] {Noodles} => {Others} 0.06024096 0.4032258 4.921727 25
Inference

No of Rules: 25
Support: 0.009
Confidence: 0.33
Lift: 4.03
Inference: 33% of probability that 0.2% of total no of customers buys both
Noodles withvegetables, Raw chiknen,Milk etc.Lift is greater than 1,henceforth
this sales case denotes complementary effect(i.e.,) People who buysNoodles also
buy all these products.Noodles can be placed near cereals ,oil,onion

Sales case of Rawrice with support 0.01 and confidence 0.3

Source file:

#Sales case of Raw rice

gr_rules_Rawrice <- apriori(Marketbasket2,parameter = list(supp=0.01,conf=0.3),


appearance = list(default="rhs",lhs="Raw Rice"))

#Inspecting the rules


inspect(gr_rules_Rawrice[1:5])
#To plot the rules
plot(gr_rules_Rawrice,method="graph")
plot(gr_rules_Rawrice,method="graph",engine='interactive')
Console file
> #Sales case of Raw rice
> gr_rules_Rawrice <- apriori(Marketbasket2,parameter =
list(supp=0.01,conf=0.3),
+ appearance = list(default="rhs",lhs="Raw Rice"))
Apriori
Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen
maxlen
0.3 0.1 1 none FALSE TRUE 5 0.01 1 10
target ext
rules FALSE
Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
Absolute minimum support count: 4
set item appearances ...[1 item(s)] done [0.00s].
set transactions ...[302 item(s), 416 transaction(s)] done [0.02s].
sorting and recoding items ... [282 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [19 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].
> #Inspecting the rules
> inspect(gr_rules_Rawrice[1:5])
lhs rhs support confidence lift count
[1] {Raw Rice} => {Salad Dressings} 0.02644231 0.3142857 5.684472 11
[2] {Raw Rice} => {Regular Eggs} 0.04807692 0.5714286 9.142857 20
[3] {Raw Rice} => {Other Cereals} 0.03605769 0.4285714 6.147783 15
[4] {Raw Rice} => {Rice} 0.04326923 0.5142857 7.131429 18
[5] {Raw Rice} => {Salt} 0.03125000 0.3714286 5.150476 13
> #To plot the rules
> plot(gr_rules_Rawrice,method="graph")
> plot(gr_rules_Rawrice,method="graph",engine='interactive')
Inference
No of Rules: 19
Support: 0.077
Confidence: 0.7 approx
Lift: 9.509(2.3-9.509)
Inference: Maximum 70% of probability that 7.7% of total no of customers buys
both Raw rice with Raw mutton and Raw chicken.Lift is greater than 1,
henceforththis sales case denotes complementary effect (i.e.,) People who
buys Raw ricealso buy all these products since these foods are most preferred
by Nonvegeterians.So we can either give price bundling (combo packs) and
place them nearer or we can place it in a little distance,so people who buys
raw rice might buy some other product while searching for raw mutton and
chicken.

Sales case Papads with Support 0.005 and Confidence 0.5

Source file:

gr_rules_Papads<-apriori(Marketbasket2,parameter = list(supp=0.005,conf=0.5),appearance =
list(default="rhs",lhs="Papads"))
plot(gr_rules_Papads,method="graph")
plot(gr_rules_Papads,method="graph",engine='interactive')
inspect(gr_rules_Papads [1:10])

Console file:
> gr_rules_Papads<-apriori(Marketbasket2,parameter =
list(supp=0.005,conf=0.5),appearance = list(default="rhs",lhs="Papads"))
Apriori
Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen
maxlen target ext
0.5 0.1 1 none FALSE TRUE 5 0.005 1
10 rules FALSE

Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE

Absolute minimum support count: 2

set item appearances ...[1 item(s)] done [0.00s].


set transactions ...[301 item(s), 415 transaction(s)] done [0.00s].
sorting and recoding items ... [301 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [24 rule(s)] done [0.00s].
creating S4 object ... done [0.00s].
> plot(gr_rules_Papads,method="graph")
> plot(gr_rules_Papads,method="graph",engine='interactive')
> inspect(gr_rules_Papads [1:10])
lhs rhs support confidence lift count
[1] {Papads} => {Panties} 0.012048193 1.0 83.0 5
[2] {Papads} => {Papaya} 0.012048193 1.0 83.0 5
[3] {Papads} => {Packing Materials} 0.009638554 0.8 66.4 4
[4] {Papads} => {Packing Foil} 0.009638554 0.8 66.4 4
[5] {Papads} => {Pastas} 0.007228916 0.6 49.8 3
[6] {Papads} => {Pasta} 0.007228916 0.6 49.8 3
[7] {Papads} => {OTHER} 0.007228916 0.6 49.8 3
[8] {Papads} => {Organic Fruits} 0.007228916 0.6 49.8 3
[9] {Papads} => {Oral Care Aids} 0.007228916 0.6 49.8 3
[10] {Papads} => {OliveOil} 0.007228916 0.6 49.8 3
Inference

No of Rules: 24
Support: 0.012
Confidence: 1.0
Lift: 83.5
Inference: 100% of probability that 12% of total no of customers buys both
Papads with oil ,vermicilli,dryfruits. Lift is greater than 1, henceforth
this sales case denotes complementary effect (i.e.,) People who buys papad
also buy all these productssince these foods are most preferred by Kids and
ladies in particular.So we can either give price bundling (combo packs) as
papad and oil and place them
nearer or we can place it in a little distance,so people who buys papad might
buy some other products like dry fruits while searching for olive
oil,pasta,oraganic fruits