MCPcopy
hub / github.com/TheAlgorithms/Python / find_prefix_path

Function find_prefix_path

machine_learning/frequent_pattern_growth.py:243–276  ·  view source on GitHub ↗

Find the conditional pattern base for a given base pattern. Args: base_pat: The base pattern for which to find the conditional pattern base. tree_node: The node in the FP-Tree. Example: >>> data_set = [ ... ['A', 'B', 'C'], ... ['A', 'C'], ...

(base_pat: frozenset, tree_node: TreeNode | None)

Source from the content-addressed store, hash-verified

241
242
243def find_prefix_path(base_pat: frozenset, tree_node: TreeNode | None) -> dict: # noqa: ARG001
244 """
245 Find the conditional pattern base for a given base pattern.
246
247 Args:
248 base_pat: The base pattern for which to find the conditional pattern base.
249 tree_node: The node in the FP-Tree.
250
251 Example:
252 >>> data_set = [
253 ... ['A', 'B', 'C'],
254 ... ['A', 'C'],
255 ... ['A', 'B', 'E'],
256 ... ['A', 'B', 'C', 'E'],
257 ... ['B', 'E']
258 ... ]
259 >>> min_sup = 2
260 >>> fp_tree, header_table = create_tree(data_set, min_sup)
261 >>> fp_tree
262 TreeNode('Null Set', 1, None)
263 >>> len(header_table)
264 4
265 >>> base_pattern = frozenset(['A'])
266 >>> sorted(find_prefix_path(base_pattern, fp_tree.children['A']))
267 []
268 """
269 cond_pats: dict = {}
270 while tree_node is not None:
271 prefix_path: list = []
272 ascend_tree(tree_node, prefix_path)
273 if len(prefix_path) > 1:
274 cond_pats[frozenset(prefix_path[1:])] = tree_node.count
275 tree_node = tree_node.node_link
276 return cond_pats
277
278
279def mine_tree(

Callers 1

mine_treeFunction · 0.85

Calls 1

ascend_treeFunction · 0.85

Tested by

no test coverage detected