Apriori icon indicating copy to clipboard operation
Apriori copied to clipboard

wrong syntax

Open albertoarturovergani opened this issue 9 years ago • 10 comments

hi, I run your code but I have received this message

File "apriori.py", line 118 for item, support in sorted(items, key=lambda (item, support): support): ^ SyntaxError: invalid syntax

Where is the error?

albertoarturovergani avatar Feb 08 '16 15:02 albertoarturovergani

Still gives me an error on for item, support in sorted(items,key=support:items[1]): .......................................................................^ (on the colon)

maxawad avatar Apr 24 '16 22:04 maxawad

try to replace this line with for item, support in sorted(items, key=lambda support: support[1])

Fan-Feng avatar May 04 '16 09:05 Fan-Feng

Thanks faithfeng, that works for printing the item sets. I have a related issue however printing the rules, in Python 3 ("tuple unpacking not supported in Python 3").

How to apply this pattern to the line below to print the rules?

for rule, confidence in sorted(rules, key=lambda (rule, confidence): confidence):

boris314159 avatar Dec 06 '16 18:12 boris314159

For python 3, I found a fix that worked for me on both prints: Change your sorted to sorted(items, key=operator.itemgetter(1)) and it should sort by values and then print correctly. Add reverse=True argument to change the order.

import operator

def printResults(items, rules):
    for item, support in sorted(items, key=operator.itemgetter(1)):
        print("item: %s , %.3f" % (str(item), support))
    print("\n------------------------ RULES:")
    for rule, confidence in sorted(rules, key=operator.itemgetter(1)):
        pre, post = rule
        print("Rule: %s ==> %s , %.3f" % (str(pre), str(post), confidence))

thomasjhuang avatar Apr 17 '17 02:04 thomasjhuang

hello faithefeng, I also have the error issue, I replaced the line by "for item, support in sorted(items, key=lambda support: support[1])" could you advise?

thx

leleabc avatar Nov 22 '17 20:11 leleabc

for key, value in largeSet.items()[1:]:

TypeError: 'dict_items' object is not subscriptable

hichembahloul79 avatar Jan 05 '18 10:01 hichembahloul79

for key, value in largeSet.items()[1:]:

TypeError: 'dict_items' object is not subscriptable

please tell me how can i resolve this

smitapeter avatar Feb 11 '18 15:02 smitapeter

Please help me solve the above problem

smitapeter avatar Feb 15 '18 14:02 smitapeter

@smitapeter use it for key, value in list(largeSet.items())[1:]:

Vipinsing27 avatar Apr 06 '18 00:04 Vipinsing27

@Vipinsing27 Thank you, that worked for me!

TheIdanLapid avatar Apr 14 '18 06:04 TheIdanLapid