R:Apriori算法没有找到任何关联规则
我生成了一个包含两个不同列的数据集:与客户关联的ID列和与其活动产品关联的另一列:R:Apriori算法没有找到任何关联规则,r,data-science,prediction,apriori,R,Data Science,Prediction,Apriori,我生成了一个包含两个不同列的数据集:与客户关联的ID列和与其活动产品关联的另一列: head(df_itemList) ID PRD_LISTE 1 1 A,B,C 3 2 C,D 4 3 A,B 5 4 A,B,C,D,E 7 5 B,A,D 8 6 A,C,D 我只选择拥有多个产品的客户。总共有589.454行,有16种不同的产品 接下来,我将da
head(df_itemList)
ID PRD_LISTE
1 1 A,B,C
3 2 C,D
4 3 A,B
5 4 A,B,C,D,E
7 5 B,A,D
8 6 A,C,D
我只选择拥有多个产品的客户。总共有589.454行,有16种不同的产品
接下来,我将data.frame写入csv文件,如下所示:
df_itemList$ID <- NULL
colnames(df_itemList) <- c("itemList")
write.csv(df_itemList, "Basket_List_13-08-2020.csv", row.names = TRUE)
现在,我尝试运行apriori算法:
basket_rules <- apriori(txn, parameter = list(sup = 1e-15,
conf = 1e-15, minlen = 2, target="rules"))
即使支持率和信心都低得离谱,也不会产生任何规则
summary(basket_rules)
set of 0 rules
这真的是因为我的数据集吗?还是我的代码中有错误?您的摘要显示数据没有正确读入:
most frequent items:
A,C A,B C,F C,D
57894 32150 31367 29434
A,B,C (Other)
29035 409575
看起来“A,C”是作为一项读取的,但它应该是两项“A”和“C”。分隔字符不起作用。我想这可能是因为文件中有引号。确保
Basket\u List\u 13-08-2020.csv
看起来正确。此外,在阅读交易记录时,您需要使用skip=1
跳过第一行(标题)。@Michael我现在非常肯定我正在阅读的.csv文件有问题。因为还有其他人也经历过类似的问题,我猜这是错误的常见原因。您能描述一下.csv文件读入时的样子吗
当输入
数据时,我想就是这样。.csv需要在不同的列中包含不同的项。
Apriori
Parameter specification:
confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext
0.01 0.1 1 none FALSE TRUE 5 1e-15 2 10 rules TRUE
Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
Absolute minimum support count: 0
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[1737 item(s), 589455 transaction(s)] done [0.20s].
sorting and recoding items ... [1737 item(s)] done [0.00s].
creating transaction tree ... done [0.16s].
checking subsets of size 1 done [0.00s].
writing ... [0 rule(s)] done [0.00s].
creating S4 object ... done [0.04s].
summary(basket_rules)
set of 0 rules
most frequent items:
A,C A,B C,F C,D
57894 32150 31367 29434
A,B,C (Other)
29035 409575
X Prd
1 A
2 A,B
3 B,A
4 B
5 C
most frequent items:
A B C A,B B,A
1256 1235 456 235 125