Confidence calculation in association rule [closed]

2024/12/4 1:21: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:passelse: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:',confelse:conf = supportData[freqSet]/supportData[tuple(freqsetlist)[:]]if conf >= 0.1:print freqsetlist,'-->',conseq,'conf:',confOutputKeyError: ('R','K')

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

Answer

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)'

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.

Edit: 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).

https://en.xdnf.cn/q/120727.html

Related Q&A

How to write the names that start with A - L to one file and the rest to another?

Hello my assignment is :Create a system that allows the user to enter their name, title, surname, Dob, email and phone number. Once details are submitted, they should be written to a file. Surnames tha…

How is it possible to use a while loop to print even numbers 2 through 100?

I am a beginner and I am stuck on this problem, "Write a python code that uses a while loop to print even numbers from 2 through 100. Hint ConsecutiveEven differ by 2."Here is what I came up …

Issue with buttons not functioning after start of program

I am new and learning python 3.6 and Ive almost completed my first code project. After doing an exhaustive search to resolve my problem I have not been able to find the answer to what I am sure is a si…

explanation of C implementation pythons len function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

How to compare the attributes start with $ in 2 functions and display match or mismatch

My input file contain attributes if(match($OPTION_EnableDetails, "1") or match($OPTION_EnableDetails_juniper, "1")) {details($juniFileXferStatus,$juniFileXferTimeStamp,$juniFileXfer…

Python comparing elements in two lists

I have two lists:a - dictionary which contains keywords such as ["impeccable", "obvious", "fantastic", "evident"] as elements of the listb - sentences which cont…

Remove all keys that have values of N/A, -, or empty strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Sorting algorithms more efficient than bubble sort [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

How can I return the odd numbers of a list, using only recursion in Python? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

TypeError: int object is not iterable; Python 2.7

Here is my code:def numbers_in_lists(string):num = int(string)l = list(num)return lstring = 543987When i run it:print numbers_in_lists(string)I have the following error:l = list(num) TypeError: int obj…