信心在计算关联规则 [英] Confidence calculation in association rule
问题描述
supportData = {('ELF'): 0.75, ('CAT'): 0.75, ('BAT', 'CAT', 'ELF'): 0.5, ('ARK', 'BAT'): 0.25, ('ARK', 'ELF'): 0.25, ('CAT', 'ELF'): 0.5, ('DOG'): 0.25, ('BAT', 'CAT'): 0.5, ('BAT', 'ELF'): 0.75, ('ARK'): 0.5, ('ARK', 'CAT'): 0.5, ('BAT'): 0.75}
L = [('ARK'), ('CAT'), ('CAT'), ('ELF'),('ARK', 'CAT'), ('BAT', 'ELF'), ('BAT', 'CAT'), ('CAT', 'ELF'),('BAT', 'CAT', 'ELF')]
for freqSet in L:
H = list(freqSet)
if len(H) == 1:
pass
else:
for conseq in H:
freqsetlist = list(freqSet)
freqsetlist.remove(conseq)
if len(freqsetlist) == 1:
conf = supportData[freqSet]/supportData[tuple(freqsetlist)[0]]
if conf >= 0.1:
print freqsetlist,'-->',conseq,'conf:',conf
else:
conf = supportData[freqSet]/supportData[tuple(freqsetlist)[:]]
if conf >= 0.1:
print freqsetlist,'-->',conseq,'conf:',conf
Output
KeyError: ('R','K')
有人能说出为什么我收到这个错误?这似乎错误发生时,len个(freqsetlist)是> 1。这与3元
Can someone point out why I am getting this error? It seems the error occur when len(freqsetlist) is > 1. That is when calculating tuple with 3 element
推荐答案
这是对象的再presentation,如果你想要一个不同的再presentation,你将不得不自己构造它:
That is the representation of the object, if you want a different representation, you will have to construct it yourself:
>>> k = ['van']
>>> "({})".format(", ".join(k))
'(van)'
请注意,这意味着你使用一个对象作为程序的一部分,Python的重新presentation,这是一个坏主意,你应该始终建立你所需要的人工,而不是尝试使用Python的重新presentation,其目的是用于调试。
Note that this implies you are using Python's representation of an object as a part of your program, this is a bad idea, and you should always construct what you need manually rather than try and use Python's representation, which is intended for debugging.
编辑:逗号是显示它是一个元组,括号内为默认情况下,意味着操作,而不是元组的分组Python的方式。你可以使自己的元组的子类,并修改 __再版__()
/ __ STR __()
如果你真的想要的,但将是难以置信的毫无意义的(和unpythonic在的情况下, __ __再版()
,因为它应该评估的对象)。
The comma is Python's way of showing it's a tuple, as brackets signify grouping of operations rather than tuples by default. You could make your own tuple subclass and change the __repr__()
/__str__()
if you really wanted, but that would be incredibly pointless (and unpythonic in the case of __repr__()
as it should evaluate to the object).
这篇关于信心在计算关联规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!