Example #1
0
File: fk1f1.py Project: frecar/dw
def fk1f1(transactions, k=0, support_count=0):
    itemSets = candidate_generations(transactions, k - 1)
    kmin1Sets = get_k_sets(itemSets, k - 1)
    k1itemSets = get_k_sets(itemSets, 1)

    for itemSet in itemSets:
        for transaction in transactions:
            if itemSet.items_in(transaction.items):
                itemSet.support_count += 1

    candidates = []

    kmin1Sets = prune(kmin1Sets, 3)
    k1itemSets = prune(k1itemSets, 3)

    for set in kmin1Sets:
        for s in k1itemSets:
            if s.items[0] not in set.items:
                itemSet = ItemSet()
                itemSet.items.extend(set.items)
                itemSet.items.extend(s.items)
                if itemSet not in candidates:
                    if every_items_appear_in_frequent_item_set(itemSet.items, kmin1Sets):
                        candidates.append(itemSet)

    return candidates
Example #2
0
File: fk1fk1.py Project: frecar/dw
def fk1fk1(transactions, k=0, support_count=0):
    itemSets = candidate_generations(transactions, k - 1)
    k1min1Sets = get_k_sets(itemSets, k - 1)
    k1min2Sets = get_k_sets(itemSets, k- 1)

    for itemSet in itemSets:
        for transaction in transactions:
            if itemSet.items_in(transaction.items):
                itemSet.support_count += 1

    candidates = []

    k1min1Sets = prune(k1min1Sets, 3)
    k1min2Sets = prune(k1min2Sets, 3)

    for sett in k1min1Sets:
        for s in k1min2Sets:

            s.items = sorted(s.items)
            sett.items = sorted(sett.items)

            if s.items[0] == sett.items[0]:
                itemSet = ItemSet()
                itemSet.items.extend(sett.items[1:])
                itemSet.items.extend(s.items)

                if itemSet not in candidates and len(set(itemSet.items))>= k:
                    candidates.append(itemSet)

    return candidates
Example #3
0
def bruteforce(transactions, k=0, support_count = 0):
    itemSets = candidate_generations(transactions, k)
    result = []

    for itemSet in itemSets:
        for transaction in transactions:
            if itemSet.items_in(transaction.items):
                itemSet.support_count += 1


    #for itemSet in itemSets:
    #    print itemSet.items, itemSet.support_count

    itemSets = prune(itemSets, 2)
    itemSets = get_k_sets(itemSets, 3)

    return itemSets