TransacID | Bag | Blush | Nail Polish | Brushes | Concealer | Eyebrow Pencils | Bronzer |
1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
2 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
3 | 0 | 1 | 0 | 0 | 1 | 1 | 1 |
4 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
5 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
6 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
7 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
8 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
9 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
10 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
11 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
12 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
Association Rules Execution through XLMiner
Steps to follow in XLMiner
Step 1:
Select XLminer -> Associate -> Association Rules
Step 2:
In Association Rules box select the worksheet where the cosmetics data present and check the box “Data in binary matrix foramt” in Input Data Foramt. In parameters box by default the “Minimum support” will be 20% of the total transctions. Here the total number of trasnctions are 1000 and hence the minimum support is 200. Minimum Confidence should be given in input. Here the input value is 40%. Generally the acceptable confidence level is more than 50%.
Step 3:
The below are the input details.
Step 4:
List of Rules in Sorted order of Lift Ratio.
Steps to follow in R
#Specify the libraries required
library("xlsx")
library("Matrix")
library("arules")
#library("arulesViz")
#Set working directory
setwd("J:\\ISB Business Analytics\\Data Mining\\Data Mining Assignment 2")
#Read the data
mydata<-read.xlsx("Cosmetics.xls", sheetName = "Sheet1")
#first records of data
head(mydata)
## Trans.. Bag Blush Nail.Polish Brushes Concealer Eyebrow.Pencils Bronzer
## 1 1 0 1 1 1 1 0 1
## 2 2 0 0 1 0 1 0 1
## 3 3 0 1 0 0 1 1 1
## 4 4 0 0 1 1 1 0 1
## 5 5 0 1 0 0 1 0 1
## 6 6 0 0 0 0 1 0 0
## Lip.liner Mascara Eye.shadow Foundation Lip.Gloss Lipstick Eyeliner
## 1 1 1 0 0 0 0 1
## 2 1 0 0 1 1 0 0
## 3 1 1 1 1 1 1 0
## 4 0 0 0 1 0 0 1
## 5 1 1 1 0 1 1 0
## 6 0 0 0 0 0 0 1
#trailer records of data
tail(mydata)
## Trans.. Bag Blush Nail.Polish Brushes Concealer Eyebrow.Pencils
## 995 995 0 1 0 0 0 0
## 996 996 0 0 0 0 0 0
## 997 997 0 0 0 0 0 0
## 998 998 0 1 1 1 1 0
## 999 999 1 1 0 0 1 0
## 1000 1000 0 0 0 0 1 0
## Bronzer Lip.liner Mascara Eye.shadow Foundation Lip.Gloss Lipstick
## 995 0 0 1 1 1 1 0
## 996 0 0 0 0 0 0 0
## 997 0 0 0 0 1 1 0
## 998 0 1 0 0 1 0 1
## 999 0 0 1 1 0 0 1
## 1000 1 1 0 1 0 0 0
## Eyeliner
## 995 0
## 996 0
## 997 0
## 998 1
## 999 1
## 1000 1
#Number of rows in the data set
nrow(mydata)
## [1] 1000
#Number of columns in the data set
ncol(mydata)
## [1] 15
#Summary
summary(mydata)
## Trans.. Bag Blush Nail.Polish
## Min. : 1.0 Min. :0.000 Min. :0.000 Min. :0.00
## 1st Qu.: 250.8 1st Qu.:0.000 1st Qu.:0.000 1st Qu.:0.00
## Median : 500.5 Median :0.000 Median :0.000 Median :0.00
## Mean : 500.5 Mean :0.054 Mean :0.363 Mean :0.28
## 3rd Qu.: 750.2 3rd Qu.:0.000 3rd Qu.:1.000 3rd Qu.:1.00
## Max. :1000.0 Max. :1.000 Max. :1.000 Max. :1.00
## Brushes Concealer Eyebrow.Pencils Bronzer
## Min. :0.000 Min. :0.000 Min. :0.000 Min. :0.000
## 1st Qu.:0.000 1st Qu.:0.000 1st Qu.:0.000 1st Qu.:0.000
## Median :0.000 Median :0.000 Median :0.000 Median :0.000
## Mean :0.149 Mean :0.442 Mean :0.042 Mean :0.279
## 3rd Qu.:0.000 3rd Qu.:1.000 3rd Qu.:0.000 3rd Qu.:1.000
## Max. :1.000 Max. :1.000 Max. :1.000 Max. :1.000
## Lip.liner Mascara Eye.shadow Foundation
## Min. :0.000 Min. :0.000 Min. :0.000 Min. :0.000
## 1st Qu.:0.000 1st Qu.:0.000 1st Qu.:0.000 1st Qu.:0.000
## Median :0.000 Median :0.000 Median :0.000 Median :1.000
## Mean :0.234 Mean :0.357 Mean :0.381 Mean :0.536
## 3rd Qu.:0.000 3rd Qu.:1.000 3rd Qu.:1.000 3rd Qu.:1.000
## Max. :1.000 Max. :1.000 Max. :1.000 Max. :1.000
## Lip.Gloss Lipstick Eyeliner
## Min. :0.00 Min. :0.000 Min. :0.000
## 1st Qu.:0.00 1st Qu.:0.000 1st Qu.:0.000
## Median :0.00 Median :0.000 Median :0.000
## Mean :0.49 Mean :0.322 Mean :0.457
## 3rd Qu.:1.00 3rd Qu.:1.000 3rd Qu.:1.000
## Max. :1.00 Max. :1.000 Max. :1.000
# Apriori application
# Support will indicate the percentage of transctions, Here it's 20% and confidence is 40%
rules = apriori(as.matrix(mydata[,2:15]), parameter=list(support=0.1, confidence=0.80,minlen=2))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport support minlen maxlen
## 0.8 0.1 1 none FALSE TRUE 0.1 2 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: 100
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[14 item(s), 1000 transaction(s)] done [0.00s].
## sorting and recoding items ... [12 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [26 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules
## set of 26 rules
# Output of Apriori with first 15 rules
rules15 <- inspect(head(sort(rules, by="lift"),15))
## lhs rhs support confidence
## 1 {Brushes} => {Nail.Polish} 0.149 1.0000000
## 23 {Blush,Concealer,Eye.shadow} => {Mascara} 0.119 0.9596774
## 15 {Blush,Eye.shadow} => {Mascara} 0.169 0.9285714
## 10 {Nail.Polish,Eye.shadow} => {Mascara} 0.119 0.9083969
## 20 {Concealer,Eye.shadow} => {Mascara} 0.179 0.8905473
## 12 {Bronzer,Eye.shadow} => {Mascara} 0.124 0.8794326
## 25 {Concealer,Eye.shadow,Eyeliner} => {Mascara} 0.114 0.8769231
## 14 {Blush,Mascara} => {Eye.shadow} 0.169 0.9184783
## 8 {Eye.shadow,Lipstick} => {Mascara} 0.110 0.8527132
## 7 {Mascara,Lipstick} => {Eye.shadow} 0.110 0.9090909
## 22 {Blush,Concealer,Mascara} => {Eye.shadow} 0.119 0.9083969
## 11 {Bronzer,Mascara} => {Eye.shadow} 0.124 0.9051095
## 2 {Mascara} => {Eye.shadow} 0.321 0.8991597
## 3 {Eye.shadow} => {Mascara} 0.321 0.8425197
## 9 {Nail.Polish,Mascara} => {Eye.shadow} 0.119 0.8880597
## lift
## 1 3.571429
## 23 2.688172
## 15 2.601040
## 10 2.544529
## 20 2.494530
## 12 2.463397
## 25 2.456367
## 14 2.410704
## 8 2.388552
## 7 2.386065
## 22 2.384244
## 11 2.375615
## 2 2.359999
## 3 2.359999
## 9 2.330865
Get Answers For Free
Most questions answered within 1 hours.