Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong syntax #13

Open
albertoarturovergani opened this issue Feb 8, 2016 · 10 comments
Open

wrong syntax #13

albertoarturovergani opened this issue Feb 8, 2016 · 10 comments
Labels

Comments

@albertoarturovergani
Copy link

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?

@maxawad
Copy link

maxawad commented Apr 24, 2016

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

@Fan-Feng
Copy link

Fan-Feng commented May 4, 2016

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

@boris314159
Copy link

boris314159 commented Dec 6, 2016

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

@asaini asaini added the Bug label Jan 23, 2017
@thomasjhuang
Copy link

thomasjhuang commented Apr 17, 2017

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

@leleabc
Copy link

leleabc commented Nov 22, 2017

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

@hichembahloul79
Copy link

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

TypeError: 'dict_items' object is not subscriptable

@smitapeter
Copy link

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

TypeError: 'dict_items' object is not subscriptable

please tell me how can i resolve this

@smitapeter
Copy link

Please help me solve the above problem

@Vipinsing27
Copy link

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

@TheIdanLapid
Copy link

@Vipinsing27 Thank you, that worked for me!

muety added a commit to muety/Apriori that referenced this issue Oct 3, 2018
asaini added a commit that referenced this issue Jan 22, 2019
Fix #11, #13 and #20 and add Python3 support to apriori script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests