我有一个“集合”数据集,或者我们把它们称为组或愿望列表.集合是项的列表。
collectionId | itemdId
---------------------------------
123 | 2345
123 | 3465
123 | 876
123 | 567
123 | 980
777 | 980
777 | 332
777 | 3465
777 | 876
777 | 678
777 | 567您可以看到第876项和第980项,这两个集合(777和123)都包括在内,因此它们是很受欢迎的一对。
我的用户生成这些集合,我很想从中提取两个见解:
例如:
说很多愿望清单上都有iphone和粉红色iphone封面,还有其他配件,但我想提取出iphone +那个粉红色iphone封面是常见的“情侣”。
总之,我基本上是在做亚马逊做的事情,如果你看到一部iphone,我想建议你一个粉红色的iphone封面,因为很多其他用户都建议/喜欢这个。
我必须先比较集合之间的相似性吗?看看他们有多少共同之处?而不是用指数来评价相似性?
用mysql实现这一目标的最佳方法是什么。我也需要PHP吗?
更新:
在PHP中,我可能会做一些类似于伪代码的疯狂的事情
for total number of collection:
select all item from collection 1
select all item from collection 2
do array_interesct (c1,c2)
store the matching items
repeat...
select all item from collection 2
do array_interesct (c1,c3)
store the matching items
repeat...
...then elect all item from collection 2 and repeat all the iterations..发布于 2016-11-07 21:07:47
对于两个集合,您可以做一个联接。
select a.itemID
from my_table a
join my_table b on a.itemID = b.ItemID
where a.collection = 123
and b.collection = 777您可以尝试使用笛卡尔乘积(对于对二表)。(3 ..3)
select a.itemID
from my_table a
cross join my_table b
where a.item = b.item
and a.collection <> b.collectionhttps://stackoverflow.com/questions/40474113
复制相似问题