(self, threshold)
return patterns
Generate subtrees and mine them for patterns.
Generate subtrees and mine them for patterns.
Generate subtrees and mine them for patterns .
def _mine_sub_trees(self, threshold):
        """
        Generate subtrees and mine them for patterns.
        """
        patterns = {}
        mining_order = sorted(self.frequent.keys(),
                              key=lambda x: self.frequent[x])

        # Get items in tree in reverse order of occurrences.
        for item in mining_order:
            suffixes = []
            conditional_tree_input = []
            node = self.headers[item]

            # Follow node links to get a list of
            # all occurrences of a certain item.
            while node is not None:
                suffixes.append(node)
                node = node.link

            # For each occurrence of the item, 
            # trace the path back to the root node.
            for suffix in suffixes:
                frequency = suffix.count
                path = []
                parent = suffix.parent

                while parent.parent is not None:
                    path.append(parent.value)
                    parent = parent.parent

                for _ in range(frequency):
                    conditional_tree_input.append(path)

            # Now we have the input for a subtree,
            # so construct it and grab the patterns.
            subtree = _FPTree(conditional_tree_input, threshold,
                             item, self.frequent[item])
            subtree_patterns = subtree._mine_patterns(threshold)

            # Insert subtree patterns into main patterns dictionary.
            for pattern in subtree_patterns.keys():
                if pattern in patterns:
                    patterns[pattern] += subtree_patterns[pattern]
                else:
                    patterns[pattern] = subtree_patterns[pattern]

        return patterns
def _mine_sub_trees ( self , threshold ) : patterns = { } mining_order = sorted ( self . frequent . keys ( ) , key = lambda x : self . frequent [ x ] ) # Get items in tree in reverse order of occurrences. for item in mining_order : suffixes = [ ] conditional_tree_input = [ ] node = self . headers [ item ] # Follow node links to get a list of # all occurrences of a certain item. while node is not None : suffixes . append ( node ) node = node . link # For each occurrence of the item,  # trace the path back to the root node. for suffix in suffixes : frequency = suffix . count path = [ ] parent = suffix . parent while parent . parent is not None : path . append ( parent . value ) parent = parent . parent for _ in range ( frequency ) : conditional_tree_input . append ( path ) # Now we have the input for a subtree, # so construct it and grab the patterns. subtree = _FPTree ( conditional_tree_input , threshold , item , self . frequent [ item ] ) subtree_patterns = subtree . _mine_patterns ( threshold ) # Insert subtree patterns into main patterns dictionary. for pattern in subtree_patterns . keys ( ) : if pattern in patterns : patterns [ pattern ] += subtree_patterns [ pattern ] else : patterns [ pattern ] = subtree_patterns [ pattern ] return patterns