transactions - arules package in R , some methods won't work -
i doing function given transaction x , set of rules y, if x whole subset of y interested in cause can recommendation based on rules (i using "groceries" dataset) trying using %ain% crazy seems rstudio not recognizing it, leave code , error throws.
install.packages("arules") library(arules) myfunction <- function(t,w,z){ lav <- (t %ain% w,arr.ind=true) lav <- z[lav,] lav <- unique(lav) return (lav) } data("groceries") x <- list(c("pip fruit","root vegetables","yogurt","soda","fruit/vegetable juice")) reglas = apriori(groceries, parameter=list(supp=0.0006, conf=0.98)) t <- as(x,"transactions") z <- slot(reglas,"rhs") w <- slot(reglas,"lhs") inspect(myfunction(t,w,z)) and error:
error in evaluating argument 'x' in selecting method function 'which': error in (function (classes, fdef, mtable) : unable find inherited method function ‘%ain%’ signature ‘"transactions", "itemmatrix"’
the error says all.
error in evaluating argument 'x' in selecting method function 'which': error in (function (classes, fdef, mtable) : unable find inherited method function ‘%ain%’ signature ‘"transactions", "itemmatrix"’
?'%ain%' says %ain% defined signature(x = "itemmatrix", table = "character").
in case, x has class 'transactions', not 'itemmatrix'. , table w has class "itemmatrix", not "character".
if want see if of itemsets in w contain of items in t ('pip fruit', etc), have to
w %ain% t # not t %ain% w where t character vector (i.e. x[[1]] in example), you'd have write extracts character vector 'transations' class.
if opposite direction want (t %ain% w), have somehow coerce t (class "transactions") itemmatrix, , coerce w (class "itemmatrix") character vector.
also, think might misunderstanding %ain% does:
returns logical vector indicating if row (itemset) in ‘x’ contains any of items specified in ‘table’.
so arr.ind in which has no effect here - result of %ain% not matrix vector.
Comments
Post a Comment