Open albertoarturovergani opened 8 years ago
Still gives me an error on for item, support in sorted(items,key=support:items[1]): .......................................................................^ (on the colon)
try to replace this line with for item, support in sorted(items, key=lambda support: support[1])
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):
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))
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
for key, value in largeSet.items()[1:]:
TypeError: 'dict_items' object is not subscriptable
for key, value in largeSet.items()[1:]:
TypeError: 'dict_items' object is not subscriptable
please tell me how can i resolve this
Please help me solve the above problem
@smitapeter use it for key, value in list(largeSet.items())[1:]:
@Vipinsing27 Thank you, that worked for me!
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?