apply apriori on it by using data generator but how can I print results

24 Views Asked by At

Here is my code for my large dataset with more than 400000 rows and 18 columns.

def data_generator(df):
  """
  Data generator, needs to return a generator to be called several times.
  Use this approach if data is too large to fit in memory.
  """
  def data_gen():
        yield [tuple(row) for row in df.values.tolist()]

  return data_gen
records=data_generator(df)
iterator = iter(association_rules)
while True:
  try:
    rule = next(iterator)
    print(rule)
  except StopIteration:
    break

Traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-e21c60b11a4d> in <cell line: 1>()
      1 while True:
      2   try:
----> 3     rule = next(iterator)
      4     print(rule)
      5   except StopIteration:

2 frames
/usr/local/lib/python3.10/dist-packages/apyori.py in __init__(self, transactions)
     41         self.__transaction_index_map = {}
     42 
---> 43         for transaction in transactions:
     44             self.add_transaction(transaction)
     45 

TypeError: 'function' object is not iterable
0

There are 0 best solutions below