Dictionary 从边缘列表在Python中创建Map Reduce函数
我需要一些帮助,从边缘列表创建Python中的Map Reduce函数 鉴于以下清单:Dictionary 从边缘列表在Python中创建Map Reduce函数,dictionary,mapreduce,key,Dictionary,Mapreduce,Key,我需要一些帮助,从边缘列表创建Python中的Map Reduce函数 鉴于以下清单: A,B A,C A,D B,C C,A C,B D,A 我的代码应该遵循下面的格式。我的目标是显示学位列表以及学位计数 map(key, value): //key: document name; value: text of the document for each word w in value: emit(w, 1) reduce(key, values): //key:
A,B
A,C
A,D
B,C
C,A
C,B
D,A
我的代码应该遵循下面的格式。我的目标是显示学位列表以及学位计数
map(key, value):
//key: document name; value: text of the document
for each word w in value:
emit(w, 1)
reduce(key, values):
//key: a word; value: an iterator over counts
result = 0
for each count v in values:
result += v
emit(key, result)
循环对我来说一直是一种挣扎。有人能给我指出正确的方向吗
输出应如下所示:
Degree Count
1 2
2 1
3 1
该代码应适用于格式类似的任何数据集
因此,据我所知,我需要计算每个字母配对的不同值的数量——这将是“度”(例如,A是度3),然后根据度对这些值进行合计——这将是“计数”
密钥可能是一对值吗
map(key, value):
//key: document name; value: text of the document
for each word w in value:
emit([x,y], 1)
我不确定MapReduce是否是解决此问题的最佳方法,但我认为以下内容是有意义的 首先将每个顶点边对映射到(顶点,1)。然后通过对每个顶点的计数求和来减少
map(key, value):
//key: vertex; value: edge
emit(key, 1)
reduce(key, values):
//key: vertex; value: an iterator over counts
result = 0
for each count v in values:
result += v
emit(key, result)
这假设输入行是唯一的。好像您发布了单词计数示例。输入和所需输出中的列标签是什么?