Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.1 Association Concepts: A sample of transaction data has 7 transactions: • Bre

ID: 3330322 • Letter: 1

Question

1.1 Association Concepts:
A sample of transaction data has 7 transactions:
• Bread, Milk, Chips, Mustard
• Beer, Diaper, Bread, Eggs
• Beer, Coke, Diaper, Milk
• Beer, Bread, Diaper, Milk, Chips
• Coke, Bread, Diaper, Milk
• Beer, Bread, Diaper, Milk, Mustard
• Coke, Bread, Diaper, Milk

The minimum support threshold for items is set as 0.6. Use the apriori algorithm to find the frequent items and a list of rules. Show all steps and compute the support, confidence and lift values for the constructed rules

Explanation / Answer

I am using R software to solve this problem.
First we can create a csv file and store the given data like below in Data.csv:

Bread, Milk, Chips, Mustard
Beer, Diaper, Bread, Eggs
Beer, Coke, Diaper, Milk
Beer, Bread, Diaper, Milk, Chips
Coke, Bread, Diaper, Milk
Beer, Bread, Diaper, Milk, Mustard
Coke, Bread, Diaper, Milk

arules package in R can be used for doing association analysis.
First we can read the data using read.transactions() function in R.

Data <- read.transactions("Data.csv", sep = ",")

Apriori algorithm can be be fit using the apriori function in R.
support paramteter is set to 0.6.
It is helpful to set minlen = 2 to eliminate rules that contain fewer than two items. This prevents uninteresting rules from being created simply because the item is purchased frequently.
Setting confidence parameter to 0.25.

#Fit apriori algorithm
DataRules <- apriori(Data, parameter = list(support=0.6, confidence=0.25, minlen=2))
inspect(DataRules)

lhs rhs support confidence lift
[1] {Bread} => {Milk} 0.7142857 0.8333333 0.9722222
[2] {Milk} => {Bread} 0.7142857 0.8333333 0.9722222
[3] {Bread} => {Diaper} 0.7142857 0.8333333 0.9722222
[4] {Diaper} => {Bread} 0.7142857 0.8333333 0.9722222
[5] {Milk} => {Diaper} 0.7142857 0.8333333 0.9722222
[6] {Diaper} => {Milk} 0.7142857 0.8333333 0.9722222

These are the set of rules given by the apriori algorithm.