Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up imports and some changes #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions mlfromscratch/unsupervised_learning/fp_growth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import division, print_function
import numpy as np
import itertools


class FPTreeNode():
def __init__(self, item=None, support=1):
Expand All @@ -22,11 +19,11 @@ class FPGrowth():

Parameters:
-----------
min_sup: float
The minimum fraction of transactions an itemets needs to
min_sup: int
The minimum transactions an itemset needs to
occur in to be deemed frequent
"""
def __init__(self, min_sup=0.3):
def __init__(self, min_sup=1):
self.min_sup = min_sup
# The root of the initial FP Growth Tree
self.tree_root = None
Expand Down Expand Up @@ -147,7 +144,7 @@ def _get_itemset_key(self, itemset):
itemset_key = str(itemset[0])
return itemset_key

def _determine_frequent_itemsets(self, conditional_database, suffix):
def _determine_frequent_itemsets(self, conditional_database, suffix=None):
# Calculate new frequent items from the conditional database
# of suffix
frequent_items = self._get_frequent_items(conditional_database)
Expand Down Expand Up @@ -191,7 +188,7 @@ def find_frequent_itemsets(self, transactions, suffix=None, show_tree=False):
print ("FP-Growth Tree:")
self.print_tree(self.tree_root)

self._determine_frequent_itemsets(transactions, suffix=None)
self._determine_frequent_itemsets(transactions, suffix)

return self.frequent_itemsets