File tree 1 file changed +26
-2
lines changed
mlxtend/frequent_patterns
1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import numpy as np
8
8
import pandas as pd
9
- import pygtrie
10
9
from ..frequent_patterns import fpcommon as fpc
11
10
12
11
12
+ class _FixedLengthTrie :
13
+ __slots__ = ("root" )
14
+
15
+ def __init__ (self , combinations ):
16
+ self .root = dict ()
17
+ for combination in combinations :
18
+ current = self .root
19
+ for item in combination :
20
+ try :
21
+ current = current [item ]
22
+ except KeyError :
23
+ next_node = dict ()
24
+ current [item ] = next_node
25
+ current = next_node
26
+
27
+ def __contains__ (self , combination ):
28
+ current = self .root
29
+ try :
30
+ for item in combination :
31
+ current = current [item ]
32
+ return True
33
+ except KeyError :
34
+ return False
35
+
36
+
13
37
def generate_new_combinations (old_combinations ):
14
38
"""
15
39
Generator of all combinations based on the last state of Apriori algorithm
@@ -44,7 +68,7 @@ def generate_new_combinations(old_combinations):
44
68
"""
45
69
46
70
length = len (old_combinations )
47
- trie = pygtrie . Trie ( list ( zip ( old_combinations , [ 1 ] * length )) )
71
+ trie = _FixedLengthTrie ( old_combinations )
48
72
for i , old_combination in enumerate (old_combinations ):
49
73
* head_i , _ = old_combination
50
74
j = i + 1
You can’t perform that action at this time.
0 commit comments