信心在计算关联规则

编程入门 行业动态 更新时间:2024-10-14 12:25:16
本文介绍了信心在计算关联规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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).

更多推荐

信心在计算关联规则

本文发布于:2023-11-30 17:22:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信心   规则

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!