【发布时间】:2015-01-13 03:52:36
【问题描述】:
我知道使用 map reduce 无法计算两个文档的 Jaccard 相似度,因为 map 只取一项。
我想计算文档字段元素的相似度。这可以使用map reduce吗?我看不到从当前点发射什么。
输入:
{'_id': 'foobar1',
'categories': ['one', 'two', 'three']}
{'_id': 'foobar2',
'categories': ['one']}
{'_id': 'foobar3',
'categories': ['one', 'two']}
我现在想计算类别one、two 和three 彼此之间的相似程度,考虑到它们所属的文档。这也可能是在以下集合中找到文档之间的相似性的状态(只是在理想情况下,我不必重新计算我的数据到这个集合)。
{'_id': 'one'
'documents': ['foobar1', 'foobar2', 'foobar3']}
{'_id': 'two',
'categories': ['foobar1', 'foobar3']}
{'_id': 'three',
'categories': ['foobar1']}
期望的输出:
{('one', 'two'): 2/3,
('one', 'three'): 1/3,
('two', 'three'): 1/2}
这是否可以使用 map reduce 以及如何实现?
到目前为止,我从地图中发出类似:
[{('one', 'two'): 1},
{('one', 'three'): 1},
{('two', 'three'): 1},
{('one', 'two'): 1}]
但是当然在reduce中我只能计算总和,因为我不知道S('one')和S('three')的并集是什么。
我是否必须在 map-reduce 之后重新计算总和,或者我可以改变我的方法以在 0 和 1 之间进行相似性(就像 Jaccard 那样)?
免责声明:尽管它可能看起来像大学任务,但事实并非如此。这是一个个人项目。
【问题讨论】: