我正在使用R
中的arules
包来提取一些关联规则,并希望按左侧(lhs(的长度进行过滤。
我尝试使用子集但没有成功。
这是我的模式和尝试:
trans<-read.transactions(file='file.csv', format="single", sep=",",cols=c("userid","target"))
inspect(head(trans,3))
rules<-apriori(trans,parameter=list(support=0.06, confidence=0.5,minlen=3,maxlen=6))
# sort by support
top.support <- sort(rules, decreasing = TRUE, na.last = NA, by = "support")
这就是我正在做的:
subset(rules,subset=length(lhs)==5) # not working. it return set of 0 rules
有什么建议吗?
length
为您提供规则的数量。您需要改用size
。
subset(rules,subset = size(lhs) == 5)