Skip to content

Commit 680e2d8

Browse files
committed
Revert "Alternate implementation"
This reverts commit e395333e70fb3c7ae92fa1898ccd070dbbdc2ffd. Alternate implementation is much more complex and does not seem to provide performance improvements.
1 parent 4efeb8c commit 680e2d8

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

mlxtend/frequent_patterns/apriori.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
# License: BSD 3 clause
66

7-
import itertools
87
import numpy as np
98
import pandas as pd
109
from ..frequent_patterns import fpcommon as fpc
@@ -43,26 +42,17 @@ def generate_new_combinations(old_combinations):
4342
4443
"""
4544

46-
if old_combinations.shape[1] == 1:
47-
for pair in itertools.combinations(old_combinations.reshape(-1), 2):
48-
yield from pair
49-
else:
50-
length = len(old_combinations)
51-
i = 0
52-
while i < length - 1:
53-
*head_i, tail_i = old_combinations[i]
54-
tails = [tail_i]
55-
j = i + 1
56-
while j < length:
57-
*head_j, tail_j = old_combinations[j]
58-
if head_i != head_j:
59-
break
60-
tails.append(tail_j)
61-
j = j + 1
62-
for pair in itertools.combinations(tails, 2):
63-
yield from head_i
64-
yield from pair
65-
i = j
45+
length = len(old_combinations)
46+
for i, old_combination in enumerate(old_combinations):
47+
*head_i, _ = old_combination
48+
j = i + 1
49+
while j < length:
50+
*head_j, tail_j = old_combinations[j]
51+
if head_i != head_j:
52+
break
53+
yield from old_combination
54+
yield tail_j
55+
j = j + 1
6656

6757

6858
def generate_new_combinations_low_memory(old_combinations, X, min_support,

0 commit comments

Comments
 (0)