I am trying to learn the apriori machine learning algorithm from a book that uses Python, and as part of that learning, I am currently stuck with this following problem:
The following code construct seems to work fine:
Ck = [[1], [2], [3], [4], [5]]
for tranid in range(10):
for candidate in Ck:
print("Printing candidate value: ", candidate)
However, the following does not work:
Ck = [[1], [2], [3], [4], [5]]
Ck2 = map(frozenset, Ck)
for tranid in range(10):
for candidate in Ck2:
print("Printing candidate value: ", candidate)
When I map every element of my original iterable to a frozenset, I notice that the inner loop ("for candidate in Ck2") executes only once. After that it never executes. The code above without the frozenset properly loops through the inner loop 10 times. However, with frozenset mapped, I can get the inner loop to execute only once.
Please help me with fixing this. The book has mapped the iterable values to frozenset because they don't want it to be mutable for the purposes of the algorithm. I am simply trying to follow it as is.
I am using Python 3.5.1 on Anaconda (Spyder).
Please help, as I am new to both Python and Machine Learning.
Thanks and Regards, Mahesh.