Ejemplo n.º 1
0
if __name__ == "__main__":
    # Init database and field list
    db = Database(['A', 'B', 'C', 'D', 'E', 'F'])
    
    # Create transactions
    t1 = Transaction(0, frozenset(['A', 'B', 'C']))
    t2 = Transaction(1, frozenset(['A', 'C']))
    t3 = Transaction(2, frozenset(['A', 'D']))
    t4 = Transaction(3, frozenset(['B', 'E', 'F']))

    # Add transactions to database
    db.add_transaction(t1)
    db.add_transaction(t2)
    db.add_transaction(t3)
    db.add_transaction(t4)

    # Output database
    db.print_as_set()
    db.print_as_boolean()

    # Init and run Apriory
    alg = AprioriAlgorithm(db, 0.30, 0.50)
    alg.run()

    # Print results 
    print('Support of frequent itemsets:')
    alg.print_support()

    print('Find rules:')
    alg.print_rules(top=10)