Problem:
Unable to generate apriori rules using library(arules)
on PC. When I run the following function:
rules <- apriori(df, parameter = list(supp = 0.01, conf = 0.5))
RStudio throws back the following error:
Error in asMethod(object) : column(s) 1, 2, 3, 4, 5 not logical or a factor. Discretize the columns first.
Suspected Solution:
I am almost certain the dataset must be formatted to conform to apriori
's expected input.
Dataset:
Code:
#Load and install packages
#install.packages("arules")
library(arules)
#Assign to dataframe
df <- read.csv("C:/Titanic.csv", header = TRUE, stringsAsFactors = FALSE)
#generate rules
rules <- apriori(df, parameter = list(supp = 0.01, conf = 0.5))
Attempted Solutions:
#One solution on SO was to factor
df<- sapply(df, as.factor)
#failed.
#What if I discretize the columns?
df$Passenger <- discretize(df$Passenger)
#After discretizing this column and running apriori, still get an error.
df$Class <- discretize(df$Class)
#discretize does not work on column Class
#could column 1 be a problem? Try dropping it.
df$Passenger <- NULL
#this did not work!