上使用哪种类型的列。
我想在我的数据集上的美食列上执行Apriori方法。
Cusisine柱样本:
[4] Japanese, Sushi
[5] Japanese, Korean
[6] Chinese
[7] Asian, European
[8] Seafood, Filipino, Asian, European
[9] European, Asian, Indian
[10] Filipino
[11] Filipino, Mexican
我的代码:
install.packages("arules")
library("arules")
itemsets <- apriori(dataSet$Cuisines, parameter=list(support=0.02, minlen=1, maxlen=1, target="frequent itemsets"))
但是我一直得到:
无用于向"交易"胁迫"因子"
的方法或默认方法
这里有什么问题?
在我的数据集中使用此列上使用Apriori方法是不合逻辑的吗?
如果是,我应该在?
您必须将数据转换为事务类型:
dats <- strsplit(as.character(dats$Cuisines),',',fixed=T) # split by comma
trans <- as(dats, "transactions")
inspect(trans)
items
[1] { Sushi,Japanese}
[2] { Korean,Japanese}
[3] {Chinese}
[4] { European,Asian}
[5] { Asian, European, Filipino,Seafood}
[6] { Asian, Indian,European}
[7] {Filipino}
[8] { Mexican,Filipino}
然后您可以做apriori
:
itemsets <- apriori(trans, parameter=list(support=0.3))
inspect(itemsets)
使用数据:
dats <- read.table(text =" Cuisines
[1] 'Japanese, Sushi'
[2] 'Japanese, Korean'
[3] 'Chinese'
[4] 'Asian, European'
[5] 'Seafood, Filipino, Asian, European'
[6] 'European, Asian, Indian'
[7] 'Filipino'
[8] 'Filipino, Mexican' ", header = T)