gpt4 book ai didi

r - 用项目共存频率构建一个稀疏矩阵(用于分析产品的交叉销售)

转载 作者:行者123 更新时间:2023-12-05 01:23:01 24 4
gpt4 key购买 nike

<分区>

我坚持创建一个稀疏矩阵,在其中我可以根据购物车和产品 ID 计算产品的交叉销售频率。

示例数据框:

x = data.frame(
cart_id = c("1","1","1","2","2","3","4","5","5","6"),
product_id = c("A","B","C","D","A","F","G","A","C","F")
)

最理想的输出:一个稀疏矩阵,其中包含两种产品出现在同一购物车中的次数。

enter image description here

有什么提示吗?

编辑:

两个答案都解决了问题。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com