Assignment 24
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
##
## abbreviate, write
library(arulesViz)
## Warning: package 'arulesViz' was built under R version 3.5.1
## Loading required package: grid
data <- read.csv("C:\\Users\\RISHI RAHUL\\Desktop\\DS\\8 arules\\Assignment\\myphonedata.csv")
data <- data[4:9]
class(data)
## [1] "data.frame"
colnames(data)
## [1] "red" "white" "green" "yellow" "orange" "blue"
data$red <- factor(data$red,levels = c("1","0"),labels = c("ChildBks",""))
data$white <- factor(data$white,levels = c("1","0"),labels = c("white",""))
data$green <- factor(data$green,levels = c("1","0"),labels = c("green",""))
data$yellow <- factor(data$yellow,levels = c("1","0"),labels = c("yellow",""))
data$orange <- factor(data$orange,levels = c("1","0"),labels = c("orange",""))
data$blue <- factor(data$blue,levels = c("1","0"),labels = c("blue",""))
#library(car)
#library(carData)
#library(mvinfluence)
data1 <- as(data,"transactions")
itemFrequencyPlot(data1,topN=15)

rules <- apriori(data1, parameter = list(supp = 0.005, confidence = 0.50, minlen = 2, maxlen = 4))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.5 0.1 1 none FALSE TRUE 5 0.005 2
## maxlen target ext
## 4 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 ...[0 item(s)] done [0.00s].
## set transactions ...[12 item(s), 11 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
## Warning in apriori(data1, parameter = list(supp = 0.005, confidence =
## 0.5, : Mining stopped (maxlen reached). Only patterns up to a length of 4
## returned!
## done [0.00s].
## writing ... [648 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
inspect(head(sort(rules), n = 10))
## lhs rhs support confidence lift count
## [1] {orange=} => {yellow=} 0.7272727 0.8888889 0.9777778 8
## [2] {yellow=} => {orange=} 0.7272727 0.8000000 0.9777778 8
## [3] {green=} => {yellow=} 0.7272727 0.8888889 0.9777778 8
## [4] {yellow=} => {green=} 0.7272727 0.8000000 0.9777778 8
## [5] {white=white} => {yellow=} 0.6363636 1.0000000 1.1000000 7
## [6] {yellow=} => {white=white} 0.6363636 0.7000000 1.1000000 7
## [7] {orange=} => {green=} 0.6363636 0.7777778 0.9506173 7
## [8] {green=} => {orange=} 0.6363636 0.7777778 0.9506173 7
## [9] {blue=blue} => {orange=} 0.5454545 1.0000000 1.2222222 6
## [10] {orange=} => {blue=blue} 0.5454545 0.6666667 1.2222222 6
plot(head(sort(rules, by = "lift"), n = 10), method = "graph", control = list(cex = 1.0)) #cex = font size

plot(rules)
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

plot(head(sort(rules), n = 10), method = "grouped", control = list(cex = 0.8))
## Warning: Unknown control parameters: cex
## Available control parameters (with default values):
## main = Grouped Matrix for 10 Rules
## k = 20
## rhs_max = 10
## lhs_items = 2
## aggr.fun = function (x, ...) UseMethod("mean")
## col = c("#EE0000FF", "#EE0303FF", "#EE0606FF", "#EE0909FF", "#EE0C0CFF", "#EE0F0FFF", "#EE1212FF", "#EE1515FF", "#EE1818FF", "#EE1B1BFF", "#EE1E1EFF", "#EE2222FF", "#EE2525FF", "#EE2828FF", "#EE2B2BFF", "#EE2E2EFF", "#EE3131FF", "#EE3434FF", "#EE3737FF", "#EE3A3AFF", "#EE3D3DFF", "#EE4040FF", "#EE4444FF", "#EE4747FF", "#EE4A4AFF", "#EE4D4DFF", "#EE5050FF", "#EE5353FF", "#EE5656FF", "#EE5959FF", "#EE5C5CFF", "#EE5F5FFF", "#EE6262FF", "#EE6666FF", "#EE6969FF", "#EE6C6CFF", "#EE6F6FFF", "#EE7272FF", "#EE7575FF", "#EE7878FF", "#EE7B7BFF", "#EE7E7EFF", "#EE8181FF", "#EE8484FF", "#EE8888FF", "#EE8B8BFF", "#EE8E8EFF", "#EE9191FF", "#EE9494FF", "#EE9797FF", "#EE9999FF", "#EE9B9BFF", "#EE9D9DFF", "#EE9F9FFF", "#EEA0A0FF", "#EEA2A2FF", "#EEA4A4FF", "#EEA5A5FF", "#EEA7A7FF", "#EEA9A9FF", "#EEABABFF", "#EEACACFF", "#EEAEAEFF", "#EEB0B0FF", "#EEB1B1FF", "#EEB3B3FF", "#EEB5B5FF", "#EEB7B7FF", "#EEB8B8FF", "#EEBABAFF", "#EEBCBCFF", "#EEBDBDFF", "#EEBFBFFF", "#EEC1C1FF", "#EEC3C3FF", "#EEC4C4FF", "#EEC6C6FF", "#EEC8C8FF", "#EEC9C9FF", "#EECBCBFF", "#EECDCDFF", "#EECFCFFF", "#EED0D0FF", "#EED2D2FF", "#EED4D4FF", "#EED5D5FF", "#EED7D7FF", "#EED9D9FF", "#EEDBDBFF", "#EEDCDCFF", "#EEDEDEFF", "#EEE0E0FF", "#EEE1E1FF", "#EEE3E3FF", "#EEE5E5FF", "#EEE7E7FF", "#EEE8E8FF", "#EEEAEAFF", "#EEECECFF", "#EEEEEEFF")
## reverse = TRUE
## xlab = NULL
## ylab = NULL
## legend = Size: support Color: lift
## spacing = -1
## panel.function = function (row, size, shading, spacing) { size[size == 0] <- NA shading[is.na(shading)] <- 1 grid.circle(x = c(1:length(size)), y = row, r = size/2 * (1 - spacing), default.units = "native", gp = gpar(fill = shading, col = shading, alpha = 0.9)) }
## gp_main = list(cex = 1.2, fontface = "bold", font = c(bold = 2))
## gp_labels = list(cex = 0.8)
## gp_labs = list(cex = 1.2, fontface = "bold", font = c(bold = 2))
## gp_lines = list(col = "gray", lty = 3)
## newpage = TRUE
## max.shading = NA
## engine = default
## verbose = FALSE
