【发布时间】:2016-05-24 18:15:24
【问题描述】:
我目前正在使用 arules 包执行购物篮分析。我读入的数据如下所示(但行数更多):
>data
transaction_id item
1 1 beer
2 1 beer
3 1 soda
4 2 beer
5 3 beer
6 3 fries
7 3 candy
8 4 soda
9 4 fries
然后我使用 dcast 对其进行转换并删除事务 id 列:
> Trans_Table <- dcast(data, transaction_id ~ item)
> Trans_Table$transaction_id <- NULL
它看起来像这样:
beer candy fries soda
1 2 0 0 1
2 1 0 0 0
3 1 1 1 0
4 0 0 1 1
但是当我进入“事务”类以便我可以使用 apriori 函数时,它将啤酒下的 2 转换为 1
> Transactions <- as(as.matrix(Trans_Table), "transactions")
Warning message:
In asMethod(object) :
matrix contains values other than 0 and 1! Setting all entries != 0 to 1.
有什么方法可以执行市场篮子分析并保持 2?换句话说,我希望看到 {beer} => {beer}、{beer, beer} => {soda} 和 {beer, soda} => {beer} 的规则,但目前只计算一次啤酒每笔交易,即使它被购买了两次。
有人可以帮忙吗?
【问题讨论】: