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
KeyError: ('R','K')
有人能指出爲什麼我得到這個錯誤嗎?當len(freqsetlist)> 1時發生錯誤。這就是當計算帶有3個元素的元組時關聯規則中的置信度計算
[3周後(http://stackoverflow.com/questions/13137232/confidence-calculation-in-association - 規則),不,我們仍然不能。 –