本文介绍了如何找到“相关项目"?在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们经常看到相关项目".例如,在博客中我们有相关的帖子,在书籍中我们有相关的书籍,等等.我的问题是我们如何编制这些相关性?如果只是标签,我经常会看到没有相同标签的相关项目.例如,当搜索粉红色"时,相关的商品可能带有紫色"标签.

we often see 'related items'. For instance in blogs we have related posts, in books we have related books, etc. My question is how do we compile those relevency? If it's just tag, I often see related items that does not have the same tag. For instance, when search for 'pink', a related item could have a 'purple' tag.

有人有什么主意吗?

推荐答案

有很多方法可以计算两个项目的相似度,但是对于简单的方法,请看一下Jaccard系数.

There are many ways to calculate similarity of two items, but for a straightforward method, take a look at the Jaccard Coefficient.

http://en.wikipedia.org/wiki/Jaccard_index

其中是:J(a,b)=交集(a,b)/工会(a,b)

Which is: J(a,b) = intersection(a,b)/union(a,b)

So lets say you want to compute the coefficient of two items:

Item A, which has the tags  "books, school, pencil, textbook, reading"
Item B, which has the tags  "books, reading, autobiography"

intersection(A,B) = books, reading
union(A,B) = books, school, pencil, textbook, reading, autobiography

so J(a,b) = 2/6 = .333

So the most related item to A would be the item which results in the highest Jaccard Coefficient when paired with A.

这篇关于如何找到“相关项目"?在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 09:07