如何确定 3 项集列表中是否至少有一个 2 项集?
How do I find out if at least one 2-itemsets is in a 3-itemsets list?
需要确定一个 3 项集列表是否是至少一个 2 项集的超集。每个具有频繁大小为 2 子集的 3 项集都已经在您的列表中。该列表不包含重复集。
这是我试过的最后一个代码。如果有 subsets/supersets,输出应该是一个小的集合列表。有了这段代码,我似乎得到了一个更大的列表而不是一个更小的列表。
已编辑...
itemset2 =[{'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''},
{'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}]
itemset3 =[{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}]
stuff = itemset2
final = [set(y) for y in {frozenset(x) for x in stuff}]
final
nostuff=itemset3
ablanklist=[]
ablanklist2=[]
blanklist=set()
for things in nostuff:
ablanklist.append(list(things))
for stuff in ablanklist:
for items in final:
if stuff[0] and stuff[1] in items:
print(items)
#print(final)
def is_subset(big: set, little: set):
return little - big == set()
set_a = set([1,2,3])
set_b = set([1,2])
is_subset(set_a, set_b)
编辑:
最好使用内置的 set_b.issubset(set_a)
条件是any
的简单应用。
给定 trio
来自 three-itemset
的元素
if any(pair < trio for pair in two-itemset):
会告诉您是否任何对是给定 3 元素集的子集。
需要确定一个 3 项集列表是否是至少一个 2 项集的超集。每个具有频繁大小为 2 子集的 3 项集都已经在您的列表中。该列表不包含重复集。
这是我试过的最后一个代码。如果有 subsets/supersets,输出应该是一个小的集合列表。有了这段代码,我似乎得到了一个更大的列表而不是一个更小的列表。 已编辑...
itemset2 =[{'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''},
{'', ''}, {'', ''}, {'', ''}, {'', ''}, {'', ''}]
itemset3 =[{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''},
{'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}, {'', '', ''}]
stuff = itemset2
final = [set(y) for y in {frozenset(x) for x in stuff}]
final
nostuff=itemset3
ablanklist=[]
ablanklist2=[]
blanklist=set()
for things in nostuff:
ablanklist.append(list(things))
for stuff in ablanklist:
for items in final:
if stuff[0] and stuff[1] in items:
print(items)
#print(final)
def is_subset(big: set, little: set):
return little - big == set()
set_a = set([1,2,3])
set_b = set([1,2])
is_subset(set_a, set_b)
编辑: 最好使用内置的 set_b.issubset(set_a)
条件是any
的简单应用。
给定 trio
来自 three-itemset
if any(pair < trio for pair in two-itemset):
会告诉您是否任何对是给定 3 元素集的子集。