mahout关联规则FPGrowthDriver源码分析之如何分数据
FP树的并行的大概算法就是把数据分小(并不是简单的分,分完后可以保证没有丢失频繁项),然后再使用每份小数据进行建树、挖掘树。那么mahout的FPGrowthDriver是如何分数据呢?其实前面也大概说了下,只是不是很特别的说明,在这里举例来说明:
比如如下的f-list: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] ,
事务集如下:
String[] items = splitter.split(input.toString()); OpenIntHashSet itemSet = new OpenIntHashSet(); for (String item : items) { if (fMap.containsKey(item) && !item.trim().isEmpty()) { itemSet.add(fMap.get(item)); } } IntArrayList itemArr = new IntArrayList(itemSet.size()); itemSet.keys(itemArr); itemArr.sort(); OpenIntHashSet groups = new OpenIntHashSet(); for (int j = itemArr.size() - 1; j >= 0; j--) { // generate group dependent shards int item = itemArr.get(j); int groupID = PFPGrowth.getGroup(item, maxPerGroup); if (!groups.contains(groupID)) { IntArrayList tempItems = new IntArrayList(j + 1); tempItems.addAllOfFromTo(itemArr, 0, j); context.setStatus("Parallel FPGrowth: Generating Group Dependent transactions for: " + item); wGroupID.set(groupID); context.write(wGroupID, new TransactionTree(tempItems, 1L)); } groups.add(groupID); }
分享,快乐,成长
转载请注明出处:http://blog.csdn.net/fansy1990