File tree Expand file tree Collapse file tree 1 file changed +21
-11
lines changed
mlxtend/frequent_patterns Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change 44#
55# License: BSD 3 clause
66
7+ import itertools
78import numpy as np
89import pandas as pd
910from ..frequent_patterns import fpcommon as fpc
@@ -42,17 +43,26 @@ def generate_new_combinations(old_combinations):
4243
4344 """
4445
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
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
5666
5767
5868def generate_new_combinations_low_memory (old_combinations , X , min_support ,
You can’t perform that action at this time.
0 commit comments