查找仅在最后一项中有所不同的所有频繁项目集对

时间:2012-08-30 22:20:00

标签: ruby algorithm apriori

我正在尝试实现apriori算法,并且无法编写用于生成候选项集的方法。这是此功能的屏幕截图。 enter image description here

主要问题是第2-5行。我不知道如何获得f1和f2。 f1和f2是最后一项不同的数组,f1中的最后一项小于f2中的最后一项。

有人知道如何在Ruby中编写这个吗?

1 个答案:

答案 0 :(得分:0)

f1 = [1,2,3]
f2 = [1,2,4]
z = [f1,f2].transpose

if(((z[0...(z.size-1)].collect {|el| el[0] == el[1]}.uniq == [true])) & (z[z.size-1][0] < z[z.size-1][1])) do

# f1 = f2 , except the last element, where the last f1 element is smaller than the last f2 element

end
相关问题