Пример #1
0
 def setUp(self):
     self.database = TransactionDatabase(1)
     self.database.add(Transaction(1, [1, 2, 3], 0))
     self.database.add(Transaction(2, [2, 3, 4], 1))
     self.database.add(Transaction(3, [1], 0))
     self.database.add(Transaction(4, [2], 1))
     self.database.add(Transaction(5, [2, 3, 5], 1))
Пример #2
0
 def setUp(self):
     self.database = TransactionDatabase(1)
     self.database.add(Transaction(1, [1,2,3], 0))
     self.database.add(Transaction(2, [2,3,4], 1))
     self.database.add(Transaction(3, [1], 0))
     self.database.add(Transaction(4, [2], 1))
     self.database.add(Transaction(5, [2,3, 5], 1))
Пример #3
0
class TransactionDatabaseTestCase(unittest.TestCase):
    def setUp(self):
        self.database = TransactionDatabase(1)
        self.database.add(Transaction(1, [1,2,3], 0))
        self.database.add(Transaction(2, [2,3,4], 1))
        self.database.add(Transaction(3, [1], 0))
        self.database.add(Transaction(4, [2], 1))
        self.database.add(Transaction(5, [2,3, 5], 1))

    def test_len(self):
        self.assertEquals(len(self.database), 5)

    def test_buildConditionalDatabase(self):
        cond_db = self.database.buildConditionalDatabase([1])
        self.assertEquals(len(cond_db), 2)

    def test_transactionListFromPattern(self):
        tlist = self.database.transactionListFromPattern([1])
        self.assertEquals(tlist, [1, 3])

    def test_labelSupport(self):
        self.assertEquals(self.database.labelSupport(), 0.6)

    def test_labelAndPatternSupport(self):
        # All matched
        self.assertEquals(self.database.labelAndPatternSupport([2]), 0.6)
        # One matched
        self.assertEquals(self.database.labelAndPatternSupport([5]), 0.2)

    def test_patternSupport(self):
        self.assertEquals(self.database.patternSupport([2,3,5]), 0.2)

    def test_removeTransactions(self):
        self.database.removeTransactions([3, 5])
        self.assertEquals(len(self.database), 3)

    def test_cleanAndPrune(self):
        # Not needed anymore? Add tests later
        pass
Пример #4
0
if __name__ == "__main__":
    usage = "usage: %prog [options] filename"
    parser = OptionParser(usage)
    parser.add_option("-d", "--debug",
                      action="store_true", dest="debug")

    (options, args) = parser.parse_args()

    if len(args) != 3:
        parser.error("You must give the filename, label support symbol, and minimum support.")

    print "Mining from file %s..." % args[0]
    print "Using label support symbol %s..." % args[1]
    print "Using support of %s..." % args[2]
    database = TransactionDatabase.loadFromFile(args[0],args[1],int(float(args[2])))

    miner = DDPMine(debug=False)
    miner.mine(database,int(float(args[2])))

    """
    database = TransactionDatabase.loadFromFile("test.csv")
    database.cleanAndPrune(2)
    print "Cleaned database:"
    print database
    print "\nItems in FP tree and corresponding nodes:"
    tree = FPTree()
    for t in database:
        tree.add(t)

    print str(tree)
Пример #5
0
class TransactionDatabaseTestCase(unittest.TestCase):
    def setUp(self):
        self.database = TransactionDatabase(1)
        self.database.add(Transaction(1, [1, 2, 3], 0))
        self.database.add(Transaction(2, [2, 3, 4], 1))
        self.database.add(Transaction(3, [1], 0))
        self.database.add(Transaction(4, [2], 1))
        self.database.add(Transaction(5, [2, 3, 5], 1))

    def test_len(self):
        self.assertEquals(len(self.database), 5)

    def test_buildConditionalDatabase(self):
        cond_db = self.database.buildConditionalDatabase([1])
        self.assertEquals(len(cond_db), 2)

    def test_transactionListFromPattern(self):
        tlist = self.database.transactionListFromPattern([1])
        self.assertEquals(tlist, [1, 3])

    def test_labelSupport(self):
        self.assertEquals(self.database.labelSupport(), 0.6)

    def test_labelAndPatternSupport(self):
        # All matched
        self.assertEquals(self.database.labelAndPatternSupport([2]), 0.6)
        # One matched
        self.assertEquals(self.database.labelAndPatternSupport([5]), 0.2)

    def test_patternSupport(self):
        self.assertEquals(self.database.patternSupport([2, 3, 5]), 0.2)

    def test_removeTransactions(self):
        self.database.removeTransactions([3, 5])
        self.assertEquals(len(self.database), 3)

    def test_cleanAndPrune(self):
        # Not needed anymore? Add tests later
        pass
Пример #6
0
from DDPMiner import DDPMine
from fptree import FPTree
from fptree.FPTree import *
from TransactionDatabase import TransactionDatabase
from optparse import OptionParser
import time
import codecs

# def run_ddpmine():
#     # Just some placeholder data
#     miner = DDPMine(debug=False)
#     miner.mine()

if __name__ == "__main__":

    database = TransactionDatabase.loadFromFile("./data/train_adt.csv", ['97'],
                                                100)
    data = TransactionDatabase.loadFromFile("./data/train_adt.csv", ['97'], 1)
    data1 = TransactionDatabase.loadFromFile("./data/test_adt.csv", ['97'], 1)
    # database.cleanAndPrune(2)
    # print ("Cleaned database:")
    # for transaction in database.transactions:
    #     print(str(transaction.label))
    # print ("\nItems in FP tree and corresponding nodes:")
    tree = FPTree()
    for t in database:
        tree.add(t)

    # print(str(tree))
    miner = DDPMine(debug=True)
    start = time.clock()
    Pt = miner.mine(database, 100)