a. Download the Mushroom data set from UCI repository (https://archive.ics.uci.edu/ml/datasets/Mushroom) and examine the data description file provided. Load the data set into R

library(readr)
agaricus_lepiota_data <- agaricus_lepiota_data <- read_csv("~/Downloads/agaricus-lepiota.data.txt", 
    col_names = FALSE)
## Parsed with column specification:
## cols(
##   .default = col_character()
## )
## See spec(...) for full column specifications.

b. Rename the columns according to the column names provided in the data description. Call the first column “class”.

colnames(agaricus_lepiota_data)[1]= 'class'
colnames(agaricus_lepiota_data)[2]= 'cap-shape'
colnames(agaricus_lepiota_data)[3]= 'cap-surfac'
colnames(agaricus_lepiota_data)[4]= 'cap-color'
colnames(agaricus_lepiota_data)[5]= 'bruises?'
colnames(agaricus_lepiota_data)[6]= 'odor'
colnames(agaricus_lepiota_data)[7]= 'gill-attachment'
colnames(agaricus_lepiota_data)[8]= 'gill-spacing'
colnames(agaricus_lepiota_data)[9]= 'gill-size'
colnames(agaricus_lepiota_data)[10]= 'gill-color'
colnames(agaricus_lepiota_data)[11]= 'stalk-shape'
colnames(agaricus_lepiota_data)[12]= 'stalk-root'
colnames(agaricus_lepiota_data)[13]= 'stalk-surface-above-ring'
colnames(agaricus_lepiota_data)[14]= 'stalk-surface-below-ring'
colnames(agaricus_lepiota_data)[15]= 'stalk-color-above-ring'
colnames(agaricus_lepiota_data)[16]= 'stalk-color-below-ring'
colnames(agaricus_lepiota_data)[17]= 'veil-type'
colnames(agaricus_lepiota_data)[18]= 'veil-color'
colnames(agaricus_lepiota_data)[19]= 'ring-number'
colnames(agaricus_lepiota_data)[20]= 'ring-type'
colnames(agaricus_lepiota_data)[21]= 'spore-print-color'
colnames(agaricus_lepiota_data)[22]= 'population'
colnames(agaricus_lepiota_data)[23]= 'habitat'

c. Examine the data set. Are there any missing values? Remove the columns with missing values if any.

table(is.na(agaricus_lepiota_data))
## 
##  FALSE 
## 186852

No missing values

d. Rename all factor levels using the full name according to the data dictionary (ie brown instead of b, flat instead of f for all columns. Does this increase the size of your data set in memory? Is it better to give factor levels meaningful names or short names?

Before = object.size(agaricus_lepiota_data)


agaricus_lepiota_data$class[agaricus_lepiota_data$class == "e"] = 'edible' 
agaricus_lepiota_data$class[agaricus_lepiota_data$class == "p"] = 'poisonous' 

agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "b"] = 'bell' 
agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "c"] = 'conical' 
agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "x"] = 'convex' 
agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "f"] = 'flat' 
agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "k"] = 'knobbed' 
agaricus_lepiota_data$`cap-shape`[agaricus_lepiota_data$`cap-shape` == "s"] = 'sunken' 


agaricus_lepiota_data$`cap-surfac`[agaricus_lepiota_data$`cap-surfac` == "f"] = 'fibrous' 
agaricus_lepiota_data$`cap-surfac`[agaricus_lepiota_data$`cap-surfac` == "g"] = 'grooves'
agaricus_lepiota_data$`cap-surfac`[agaricus_lepiota_data$`cap-surfac` == "y"] = 'scaly'
agaricus_lepiota_data$`cap-surfac`[agaricus_lepiota_data$`cap-surfac` == "s"] = 'smooth'


agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "n"] = 'brown'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "b"] = 'buff'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "c"] = 'cinnamon'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "g"] = 'gray'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "r"] = 'green'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "p"] = 'pink'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "u"] = 'purple'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "e"] = 'red'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "w"] = 'white'
agaricus_lepiota_data$`cap-color`[agaricus_lepiota_data$`cap-color` == "y"] = 'yellow'

agaricus_lepiota_data$`bruises?`[agaricus_lepiota_data$`bruises?` == "t"] = 'bruises'
agaricus_lepiota_data$`bruises?`[agaricus_lepiota_data$`bruises?` == "f"] = 'no'

agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "a"] = 'almond'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "l"] = 'anise'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "c"] = 'creosote'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "y"] = 'fishy'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "f"] = 'foul'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "m"] = 'musty'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "n"] = 'none'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "p"] = 'pungent'
agaricus_lepiota_data$odor[agaricus_lepiota_data$odor == "s"] = 'spicy'


agaricus_lepiota_data$`gill-attachment`[agaricus_lepiota_data$`gill-attachment`== "a"] = 'attached'
agaricus_lepiota_data$`gill-attachment`[agaricus_lepiota_data$`gill-attachment`== "d"] = 'descending'
agaricus_lepiota_data$`gill-attachment`[agaricus_lepiota_data$`gill-attachment`== "f"] = 'free'
agaricus_lepiota_data$`gill-attachment`[agaricus_lepiota_data$`gill-attachment`== "n"] = 'notched'

agaricus_lepiota_data$`gill-spacing`[agaricus_lepiota_data$`gill-spacing`== "c"] = 'close'
agaricus_lepiota_data$`gill-spacing`[agaricus_lepiota_data$`gill-spacing`== "w"] = 'crowded'
agaricus_lepiota_data$`gill-spacing`[agaricus_lepiota_data$`gill-spacing`== "d"] = 'distant'


agaricus_lepiota_data$`gill-size`[agaricus_lepiota_data$`gill-size`== "b"] = 'broad'
agaricus_lepiota_data$`gill-size`[agaricus_lepiota_data$`gill-size`== "n"] = 'narrow'


agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "k"] = 'black'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "n"] = 'brown'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "b"] = 'buff'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "h"] = 'chocolate'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "g"] = 'gray'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "r"] = 'green'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "o"] = 'orange'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "p"] = 'pink'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "u"] = 'purple'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "e"] = 'red'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "w"] = 'white'
agaricus_lepiota_data$`gill-color`[agaricus_lepiota_data$`gill-color`== "y"] = 'yellow'


agaricus_lepiota_data$`stalk-shape`[agaricus_lepiota_data$`stalk-shape`== "e"] = 'enlarging'
agaricus_lepiota_data$`stalk-shape`[agaricus_lepiota_data$`stalk-shape`== "t"] = 'tapering'


agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "b"] = 'bulbous'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "c"] = 'club'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "u"] = 'cup'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "e"] = 'equal'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "z"] = 'rhizomorphs'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "r"] = 'rooted'
agaricus_lepiota_data$`stalk-root`[agaricus_lepiota_data$`stalk-root`== "?"] = 'missing'


agaricus_lepiota_data$`stalk-surface-above-ring`[agaricus_lepiota_data$`stalk-surface-above-ring`== "f"] = 'fibrous'
agaricus_lepiota_data$`stalk-surface-above-ring`[agaricus_lepiota_data$`stalk-surface-above-ring`== "y"] = 'scaly'
agaricus_lepiota_data$`stalk-surface-above-ring`[agaricus_lepiota_data$`stalk-surface-above-ring`== "k"] = 'silky'
agaricus_lepiota_data$`stalk-surface-above-ring`[agaricus_lepiota_data$`stalk-surface-above-ring`== "s"] = 'smooth'

agaricus_lepiota_data$`stalk-surface-below-ring`[agaricus_lepiota_data$`stalk-surface-below-ring`== "f"] = 'fibrous'
agaricus_lepiota_data$`stalk-surface-below-ring`[agaricus_lepiota_data$`stalk-surface-below-ring`== "y"] = 'scaly'
agaricus_lepiota_data$`stalk-surface-below-ring`[agaricus_lepiota_data$`stalk-surface-below-ring`== "k"] = 'silky'
agaricus_lepiota_data$`stalk-surface-below-ring`[agaricus_lepiota_data$`stalk-surface-below-ring`== "s"] = 'smooth'


agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "f"] = 'fibrous'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "y"] = 'scaly'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "k"] = 'silky'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "s"] = 'smooth'


agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "n"] = 'brown'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "b"] = 'buff'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "c"] = 'cinnamon'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "g"] = 'gray'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "o"] = 'orange'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "p"] = 'pink'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "e"] = 'red'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "w"] = 'white'
agaricus_lepiota_data$`stalk-color-above-ring`[agaricus_lepiota_data$`stalk-color-above-ring`== "y"] = 'yellow'


agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "n"] = 'brown'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "b"] = 'buff'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "c"] = 'cinnamon'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "g"] = 'gray'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "o"] = 'orange'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "p"] = 'pink'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "e"] = 'red'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "w"] = 'white'
agaricus_lepiota_data$`stalk-color-below-ring`[agaricus_lepiota_data$`stalk-color-below-ring`== "y"] = 'yellow'

agaricus_lepiota_data$`veil-type`[agaricus_lepiota_data$`veil-type`== "p"] = 'partial'
agaricus_lepiota_data$`veil-type`[agaricus_lepiota_data$`veil-type`== "u"] = 'universal'


agaricus_lepiota_data$`veil-color`[agaricus_lepiota_data$`veil-color`== "n"] = 'brown'
agaricus_lepiota_data$`veil-color`[agaricus_lepiota_data$`veil-color`== "o"] = 'orange'
agaricus_lepiota_data$`veil-color`[agaricus_lepiota_data$`veil-color`== "w"] = 'white'
agaricus_lepiota_data$`veil-color`[agaricus_lepiota_data$`veil-color`== "y"] = 'yellow'

agaricus_lepiota_data$`ring-number`[agaricus_lepiota_data$`ring-number`== "n"] = 'none'
agaricus_lepiota_data$`ring-number`[agaricus_lepiota_data$`ring-number`== "o"] = 'one'
agaricus_lepiota_data$`ring-number`[agaricus_lepiota_data$`ring-number`== "t"] = 'two'


agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "c"] = 'cobwebby'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "e"] = 'evanescent'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "f"] = 'flaring'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "l"] = 'large'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "n"] = 'none'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "p"] = 'pendant'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "s"] = 'sheathing'
agaricus_lepiota_data$`ring-type`[agaricus_lepiota_data$`ring-type`== "z"] = 'zone'


agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "k"] = 'black'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "n"] = 'brown'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "b"] = 'buff'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "h"] = 'chocolate'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "r"] = 'green'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "o"] = 'orange'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "u"] = 'purple'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "w"] = 'white'
agaricus_lepiota_data$`spore-print-color`[agaricus_lepiota_data$`spore-print-color`== "y"] = 'yellow'


agaricus_lepiota_data$population[agaricus_lepiota_data$population== "a"] = 'abundant'
agaricus_lepiota_data$population[agaricus_lepiota_data$population== "c"] = 'clustered'
agaricus_lepiota_data$population[agaricus_lepiota_data$population== "n"] = 'numerous'
agaricus_lepiota_data$population[agaricus_lepiota_data$population== "s"] = 'scattered'
agaricus_lepiota_data$population[agaricus_lepiota_data$population== "v"] = 'several'
agaricus_lepiota_data$population[agaricus_lepiota_data$population== "y"] = 'solitary'


agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "g"] = 'grasses'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "l"] = 'leaves'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "m"] = 'meadows'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "p"] = 'paths'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "u"] = 'urban'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "w"] = 'waste'
agaricus_lepiota_data$habitat[agaricus_lepiota_data$habitat== "d"] = 'woods'

After = object.size(agaricus_lepiota_data)
After - Before
## 128 bytes

After changing the names of all the columns the file size increased by 128 bytes which is miniscule. In general I believe it is always important to give the lable meaningful names. Otherwise, there can be error interpreting the results and confusion.

e. Plot the frequency distribution of all the variables. Show only 5 plots of your choice for this assignment.

barplot(table(agaricus_lepiota_data$class))

barplot(table(agaricus_lepiota_data$`stalk-color-above-ring`))

barplot(table(agaricus_lepiota_data$`stalk-color-below-ring`))

barplot(table(agaricus_lepiota_data$`gill-attachment`))

barplot(table(agaricus_lepiota_data$`stalk-shape`))

f. Install (if needed) and load packages arules and arulesViz.

library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(arulesViz)
## Loading required package: grid

g. Run apriori algorithm with min support = 5% and min confidence 90%. Inspect the first 50 rules obtained. Are there any rules where the rhs and lhs are not correlated?

sapply(agaricus_lepiota_data, function(r) { class(r)})
##                    class                cap-shape               cap-surfac 
##              "character"              "character"              "character" 
##                cap-color                 bruises?                     odor 
##              "character"              "character"              "character" 
##          gill-attachment             gill-spacing                gill-size 
##              "character"              "character"              "character" 
##               gill-color              stalk-shape               stalk-root 
##              "character"              "character"              "character" 
## stalk-surface-above-ring stalk-surface-below-ring   stalk-color-above-ring 
##              "character"              "character"              "character" 
##   stalk-color-below-ring                veil-type               veil-color 
##              "character"              "character"              "character" 
##              ring-number                ring-type        spore-print-color 
##              "character"              "character"              "character" 
##               population                  habitat 
##              "character"              "character"
agaricus_lepiota_data[sapply(agaricus_lepiota_data, is.character)] <- lapply(agaricus_lepiota_data[sapply(agaricus_lepiota_data, is.character)], as.factor)


rules = apriori(agaricus_lepiota_data, parameter = list(supp = .05, conf= .9, target = "rules"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.9    0.1    1 none FALSE            TRUE       5    0.05      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 406 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[119 item(s), 8124 transaction(s)] done [0.01s].
## sorting and recoding items ... [73 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 6 7 8
## Warning in apriori(agaricus_lepiota_data, parameter = list(supp = 0.05, :
## Mining stopped (time limit reached). Only patterns up to a length of 8
## returned!
##  done [7.24s].
## writing ... [8776879 rule(s)] done [1.20s].
## creating S4 object  ... done [3.09s].
inspect(head(rules, 50))
##      lhs                               rhs                                 support confidence     lift count
## [1]  {}                             => {ring-number=one}                0.92171344  0.9217134 1.000000  7488
## [2]  {}                             => {gill-attachment=free}           0.97415066  0.9741507 1.000000  7914
## [3]  {}                             => {veil-color=white}               0.97538159  0.9753816 1.000000  7924
## [4]  {}                             => {veil-type=partial}              1.00000000  1.0000000 1.000000  8124
## [5]  {gill-color=black}             => {stalk-color-below-ring=white}   0.05022157  1.0000000 1.853102   408
## [6]  {gill-color=black}             => {stalk-color-above-ring=white}   0.05022157  1.0000000 1.819892   408
## [7]  {gill-color=black}             => {ring-number=one}                0.05022157  1.0000000 1.084936   408
## [8]  {gill-color=black}             => {gill-attachment=free}           0.05022157  1.0000000 1.026535   408
## [9]  {gill-color=black}             => {veil-color=white}               0.05022157  1.0000000 1.025240   408
## [10] {gill-color=black}             => {veil-type=partial}              0.05022157  1.0000000 1.000000   408
## [11] {stalk-color-above-ring=buff}  => {ring-type=large}                0.05317578  1.0000000 6.268519   432
## [12] {stalk-color-above-ring=buff}  => {spore-print-color=chocolate}    0.05317578  1.0000000 4.977941   432
## [13] {stalk-color-above-ring=buff}  => {odor=foul}                      0.05317578  1.0000000 3.761111   432
## [14] {stalk-color-above-ring=buff}  => {stalk-surface-below-ring=silky} 0.05317578  1.0000000 3.526042   432
## [15] {stalk-color-above-ring=buff}  => {stalk-surface-above-ring=silky} 0.05317578  1.0000000 3.424958   432
## [16] {stalk-color-above-ring=buff}  => {stalk-shape=enlarging}          0.05317578  1.0000000 2.310580   432
## [17] {stalk-color-above-ring=buff}  => {stalk-root=bulbous}             0.05317578  1.0000000 2.151483   432
## [18] {stalk-color-above-ring=buff}  => {class=poisonous}                0.05317578  1.0000000 2.074566   432
## [19] {stalk-color-above-ring=buff}  => {bruises?=no}                    0.05317578  1.0000000 1.711036   432
## [20] {stalk-color-above-ring=buff}  => {gill-size=broad}                0.05317578  1.0000000 1.447612   432
## [21] {stalk-color-above-ring=buff}  => {gill-spacing=close}             0.05317578  1.0000000 1.192601   432
## [22] {stalk-color-above-ring=buff}  => {ring-number=one}                0.05317578  1.0000000 1.084936   432
## [23] {stalk-color-above-ring=buff}  => {gill-attachment=free}           0.05317578  1.0000000 1.026535   432
## [24] {stalk-color-above-ring=buff}  => {veil-color=white}               0.05317578  1.0000000 1.025240   432
## [25] {stalk-color-above-ring=buff}  => {veil-type=partial}              0.05317578  1.0000000 1.000000   432
## [26] {stalk-color-below-ring=buff}  => {ring-type=large}                0.05317578  1.0000000 6.268519   432
## [27] {stalk-color-below-ring=buff}  => {spore-print-color=chocolate}    0.05317578  1.0000000 4.977941   432
## [28] {stalk-color-below-ring=buff}  => {odor=foul}                      0.05317578  1.0000000 3.761111   432
## [29] {stalk-color-below-ring=buff}  => {stalk-surface-below-ring=silky} 0.05317578  1.0000000 3.526042   432
## [30] {stalk-color-below-ring=buff}  => {stalk-surface-above-ring=silky} 0.05317578  1.0000000 3.424958   432
## [31] {stalk-color-below-ring=buff}  => {stalk-shape=enlarging}          0.05317578  1.0000000 2.310580   432
## [32] {stalk-color-below-ring=buff}  => {stalk-root=bulbous}             0.05317578  1.0000000 2.151483   432
## [33] {stalk-color-below-ring=buff}  => {class=poisonous}                0.05317578  1.0000000 2.074566   432
## [34] {stalk-color-below-ring=buff}  => {bruises?=no}                    0.05317578  1.0000000 1.711036   432
## [35] {stalk-color-below-ring=buff}  => {gill-size=broad}                0.05317578  1.0000000 1.447612   432
## [36] {stalk-color-below-ring=buff}  => {gill-spacing=close}             0.05317578  1.0000000 1.192601   432
## [37] {stalk-color-below-ring=buff}  => {ring-number=one}                0.05317578  1.0000000 1.084936   432
## [38] {stalk-color-below-ring=buff}  => {gill-attachment=free}           0.05317578  1.0000000 1.026535   432
## [39] {stalk-color-below-ring=buff}  => {veil-color=white}               0.05317578  1.0000000 1.025240   432
## [40] {stalk-color-below-ring=buff}  => {veil-type=partial}              0.05317578  1.0000000 1.000000   432
## [41] {stalk-color-above-ring=brown} => {ring-type=large}                0.05317578  0.9642857 6.044643   432
## [42] {stalk-color-above-ring=brown} => {spore-print-color=chocolate}    0.05317578  0.9642857 4.800158   432
## [43] {stalk-color-above-ring=brown} => {odor=foul}                      0.05317578  0.9642857 3.626786   432
## [44] {stalk-color-above-ring=brown} => {stalk-surface-below-ring=silky} 0.05317578  0.9642857 3.400112   432
## [45] {stalk-color-above-ring=brown} => {stalk-surface-above-ring=silky} 0.05317578  0.9642857 3.302638   432
## [46] {stalk-color-above-ring=brown} => {stalk-shape=enlarging}          0.05514525  1.0000000 2.310580   448
## [47] {stalk-color-above-ring=brown} => {stalk-root=bulbous}             0.05514525  1.0000000 2.151483   448
## [48] {stalk-color-above-ring=brown} => {class=poisonous}                0.05317578  0.9642857 2.000474   432
## [49] {stalk-color-above-ring=brown} => {bruises?=no}                    0.05514525  1.0000000 1.711036   448
## [50] {stalk-color-above-ring=brown} => {gill-size=broad}                0.05514525  1.0000000 1.447612   448

Yes there are quite a few instances where the lift is exactly equal to 1. This means that they are independent or eachother and not correlated.

h. Sort the rules by the lift and reinspect the first 50 rules.

inspect(sort(head(rules, 50, by = "lift" )))
##      lhs                                  rhs                  support confidence     lift count
## [1]  {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [2]  {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [3]  {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [4]  {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [5]  {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [6]  {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [7]  {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [8]  {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [9]  {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [10] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [11] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [12] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [13] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       gill-spacing=close,                                                                       
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [14] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       gill-attachment=free,                                                                     
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [15] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [16] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-type=partial,                                                                        
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [17] {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [18] {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [19] {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [20] {bruises?=bruises,                                                                         
##       gill-spacing=close,                                                                       
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [21] {bruises?=bruises,                                                                         
##       gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [22] {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [23] {bruises?=bruises,                                                                         
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-type=partial,                                                                        
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [24] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [25] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [26] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [27] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512
## [28] {class=edible,                                                                             
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [29] {class=edible,                                                                             
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [30] {class=edible,                                                                             
##       gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [31] {class=edible,                                                                             
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [32] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [33] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [34] {gill-spacing=close,                                                                       
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [35] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [36] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [37] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       veil-type=partial,                                                                        
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [38] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [39] {gill-spacing=close,                                                                       
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [40] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [41] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [42] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-above-ring=white,                                                             
##       veil-type=partial,                                                                        
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [43] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [44] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-above-ring=smooth,                                                          
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [45] {gill-attachment=free,                                                                     
##       gill-spacing=close,                                                                       
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [46] {gill-spacing=close,                                                                       
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [47] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [48] {gill-attachment=free,                                                                     
##       gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-type=partial,                                                                        
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [49] {gill-size=broad,                                                                          
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       veil-type=partial,                                                                        
##       veil-color=white,                                                                         
##       ring-number=one}                 => {stalk-root=club} 0.06302314          1 14.61151   512
## [50] {class=edible,                                                                             
##       bruises?=bruises,                                                                         
##       stalk-shape=enlarging,                                                                    
##       stalk-surface-below-ring=smooth,                                                          
##       stalk-color-below-ring=white,                                                             
##       ring-number=one,                                                                          
##       ring-type=pendant}               => {stalk-root=club} 0.06302314          1 14.61151   512

i. We are interested in rules where “class” appear on the right hand side. Rerun apriori with the parameter appearance set so only rules with class on RHS are generated.

rules2 = apriori(agaricus_lepiota_data, parameter = list(supp = .05, conf= .9, target = "rules"), appearance = list(rhs = c("class=edible", "class=poisonous"), default='lhs'))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.9    0.1    1 none FALSE            TRUE       5    0.05      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 406 
## 
## set item appearances ...[2 item(s)] done [0.00s].
## set transactions ...[119 item(s), 8124 transaction(s)] done [0.01s].
## sorting and recoding items ... [73 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 6 7 8
## Warning in apriori(agaricus_lepiota_data, parameter = list(supp = 0.05, :
## Mining stopped (time limit reached). Only patterns up to a length of 8
## returned!
##  done [6.90s].
## writing ... [587554 rule(s)] done [0.14s].
## creating S4 object  ... done [0.25s].
inspect(head(rules2, 50))
##      lhs                                 rhs                  support confidence     lift count
## [1]  {stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [2]  {stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [3]  {stalk-color-above-ring=brown}   => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [4]  {gill-color=purple}              => {class=edible}    0.05465288  0.9024390 1.742256   444
## [5]  {stalk-root=club}                => {class=edible}    0.06302314  0.9208633 1.777826   512
## [6]  {stalk-color-above-ring=gray}    => {class=edible}    0.07090103  1.0000000 1.930608   576
## [7]  {odor=spicy}                     => {class=poisonous} 0.07090103  1.0000000 2.074566   576
## [8]  {stalk-color-below-ring=gray}    => {class=edible}    0.07090103  1.0000000 1.930608   576
## [9]  {odor=fishy}                     => {class=poisonous} 0.07090103  1.0000000 2.074566   576
## [10] {ring-type=large}                => {class=poisonous} 0.15952733  1.0000000 2.074566  1296
## [11] {gill-spacing=crowded}           => {class=edible}    0.14771049  0.9146341 1.765800  1200
## [12] {spore-print-color=chocolate}    => {class=poisonous} 0.19497784  0.9705882 2.013549  1584
## [13] {gill-color=buff}                => {class=poisonous} 0.21270310  1.0000000 2.074566  1728
## [14] {odor=foul}                      => {class=poisonous} 0.26587888  1.0000000 2.074566  2160
## [15] {stalk-surface-below-ring=silky} => {class=poisonous} 0.26587888  0.9375000 1.944906  2160
## [16] {stalk-surface-above-ring=silky} => {class=poisonous} 0.27424914  0.9392917 1.948623  2228
## [17] {odor=none}                      => {class=edible}    0.41949778  0.9659864 1.864941  3408
## [18] {stalk-color-below-ring=buff,                                                             
##       ring-type=large}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [19] {stalk-color-below-ring=buff,                                                             
##       spore-print-color=chocolate}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [20] {odor=foul,                                                                               
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [21] {stalk-surface-below-ring=silky,                                                          
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [22] {stalk-surface-above-ring=silky,                                                          
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [23] {stalk-shape=enlarging,                                                                   
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [24] {stalk-root=bulbous,                                                                      
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [25] {bruises?=no,                                                                             
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [26] {gill-size=broad,                                                                         
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [27] {gill-spacing=close,                                                                      
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [28] {stalk-color-below-ring=buff,                                                             
##       ring-number=one}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [29] {gill-attachment=free,                                                                    
##       stalk-color-below-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [30] {stalk-color-below-ring=buff,                                                             
##       veil-color=white}               => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [31] {stalk-color-below-ring=buff,                                                             
##       veil-type=partial}              => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [32] {stalk-color-above-ring=buff,                                                             
##       ring-type=large}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [33] {stalk-color-above-ring=buff,                                                             
##       spore-print-color=chocolate}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [34] {odor=foul,                                                                               
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [35] {stalk-surface-below-ring=silky,                                                          
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [36] {stalk-surface-above-ring=silky,                                                          
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [37] {stalk-shape=enlarging,                                                                   
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [38] {stalk-root=bulbous,                                                                      
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [39] {bruises?=no,                                                                             
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [40] {gill-size=broad,                                                                         
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [41] {gill-spacing=close,                                                                      
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [42] {stalk-color-above-ring=buff,                                                             
##       ring-number=one}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [43] {gill-attachment=free,                                                                    
##       stalk-color-above-ring=buff}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [44] {stalk-color-above-ring=buff,                                                             
##       veil-color=white}               => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [45] {stalk-color-above-ring=buff,                                                             
##       veil-type=partial}              => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [46] {stalk-color-above-ring=brown,                                                            
##       ring-type=large}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [47] {stalk-color-above-ring=brown,                                                            
##       spore-print-color=chocolate}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [48] {odor=foul,                                                                               
##       stalk-color-above-ring=brown}   => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [49] {stalk-surface-below-ring=silky,                                                          
##       stalk-color-above-ring=brown}   => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [50] {stalk-surface-above-ring=silky,                                                          
##       stalk-color-above-ring=brown}   => {class=poisonous} 0.05317578  1.0000000 2.074566   432

j. Consider the following two rules among the output of j) Rule1: {stalk.color.above.ring=buff}=>{class=poisonous} Rule 2: {stalk.color.above.ring=buff, spore.print.color=chocolate} => {class=poisonous} Comment on interestingness of both rules.

Rule 1: has a support of 0.05317578 a confidecne of 1.0000000 and a lift of 2.074566. Meaning that there is a posative correlations. Although thinking logically the color isnt a very good indication of being poisonous or not. It might be in orrcrance alot but more research should be done to along with this association. Rule 2: interestingly enought has the same support of 0.05317578 confidence of 1.0000000 and lift of 2.074566 as the other rule except this rule has multiple associations. This seems to be headed in the right direction of assocation mining.

k. Use the function is.redundant to prune redundant rules.

inspect(head(rules2[is.redundant(rules2)], 50)) #redundant rules
##      lhs                                  rhs                  support confidence     lift count
## [1]  {stalk-color-below-ring=buff,                                                              
##       ring-type=large}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [2]  {stalk-color-below-ring=buff,                                                              
##       spore-print-color=chocolate}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [3]  {odor=foul,                                                                                
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [4]  {stalk-surface-below-ring=silky,                                                           
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [5]  {stalk-surface-above-ring=silky,                                                           
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [6]  {stalk-shape=enlarging,                                                                    
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [7]  {stalk-root=bulbous,                                                                       
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [8]  {bruises?=no,                                                                              
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [9]  {gill-size=broad,                                                                          
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [10] {gill-spacing=close,                                                                       
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [11] {stalk-color-below-ring=buff,                                                              
##       ring-number=one}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [12] {gill-attachment=free,                                                                     
##       stalk-color-below-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [13] {stalk-color-below-ring=buff,                                                              
##       veil-color=white}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [14] {stalk-color-below-ring=buff,                                                              
##       veil-type=partial}               => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [15] {stalk-color-above-ring=buff,                                                              
##       ring-type=large}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [16] {stalk-color-above-ring=buff,                                                              
##       spore-print-color=chocolate}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [17] {odor=foul,                                                                                
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [18] {stalk-surface-below-ring=silky,                                                           
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [19] {stalk-surface-above-ring=silky,                                                           
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [20] {stalk-shape=enlarging,                                                                    
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [21] {stalk-root=bulbous,                                                                       
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [22] {bruises?=no,                                                                              
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [23] {gill-size=broad,                                                                          
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [24] {gill-spacing=close,                                                                       
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [25] {stalk-color-above-ring=buff,                                                              
##       ring-number=one}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [26] {gill-attachment=free,                                                                     
##       stalk-color-above-ring=buff}     => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [27] {stalk-color-above-ring=buff,                                                              
##       veil-color=white}                => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [28] {stalk-color-above-ring=buff,                                                              
##       veil-type=partial}               => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [29] {stalk-color-above-ring=brown,                                                             
##       ring-type=large}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [30] {odor=foul,                                                                                
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [31] {stalk-shape=enlarging,                                                                    
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [32] {stalk-root=bulbous,                                                                       
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [33] {bruises?=no,                                                                              
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [34] {gill-size=broad,                                                                          
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [35] {gill-spacing=close,                                                                       
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [36] {gill-attachment=free,                                                                     
##       stalk-color-above-ring=brown}    => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [37] {stalk-color-above-ring=brown,                                                             
##       veil-color=white}                => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [38] {stalk-color-above-ring=brown,                                                             
##       veil-type=partial}               => {class=poisonous} 0.05317578  0.9642857 2.000474   432
## [39] {gill-color=purple,                                                                        
##       habitat=woods}                   => {class=edible}    0.05465288  0.9024390 1.742256   444
## [40] {gill-color=purple,                                                                        
##       stalk-root=bulbous}              => {class=edible}    0.05317578  0.9000000 1.737548   432
## [41] {gill-color=purple,                                                                        
##       ring-type=pendant}               => {class=edible}    0.05317578  0.9000000 1.737548   432
## [42] {gill-color=purple,                                                                        
##       stalk-surface-below-ring=smooth} => {class=edible}    0.05317578  0.9000000 1.737548   432
## [43] {gill-color=purple,                                                                        
##       stalk-surface-above-ring=smooth} => {class=edible}    0.05465288  0.9024390 1.742256   444
## [44] {gill-color=purple,                                                                        
##       ring-number=one}                 => {class=edible}    0.05465288  0.9024390 1.742256   444
## [45] {gill-attachment=free,                                                                     
##       gill-color=purple}               => {class=edible}    0.05465288  0.9024390 1.742256   444
## [46] {gill-color=purple,                                                                        
##       veil-color=white}                => {class=edible}    0.05465288  0.9024390 1.742256   444
## [47] {gill-color=purple,                                                                        
##       veil-type=partial}               => {class=edible}    0.05465288  0.9024390 1.742256   444
## [48] {stalk-color-below-ring=brown,                                                             
##       ring-type=large}                 => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [49] {odor=foul,                                                                                
##       stalk-color-below-ring=brown}    => {class=poisonous} 0.05317578  1.0000000 2.074566   432
## [50] {stalk-shape=enlarging,                                                                    
##       stalk-root=club}                 => {class=edible}    0.06302314  0.9208633 1.777826   512

l. Sort by decreasing order of the lift. Scatter plot the first 5000 rules (of the sorted set), using support and lift as x- and y-axis (as measures) and confidence for shading.

Top.Lift = sort(rules2[1:5000,], by = "lift", decreasing = TRUE)
plot(Top.Lift, measure=c("support", "lift"), shading="confidence")

m. Plotagraph(vertices/edges)forthefirst20rules.

plot(Top.Lift, method="graph",max = 20)
## Warning: plot: Too many rules supplied. Only plotting the best 20 rules
## using 'support' (change control parameter max if needed)