Example #1
0
def knn():
    from util import reader
    r = reader.stringSepReader("u.data", "\t")

    from util import split
    train, test1 = split.splitMatrix(r.getMatrix(), 1234567890)

    from recommender import knn
    k = knn.userKnn(train, 10)

    from util import test
    print test.hitrate(test1, k.getRec, 10)

    import cPickle
    output = open("knn.npz", "wb")
    cPickle.dump(k, output, -1)
    output.close()
Example #2
0
def svd():
    from util import reader
    r = reader.tabSepReader("u.data")

    from util import split
    train, test1 = split.split(r.getR(), 1234567890)

    from recommender import svd
    W, H = svd.learnModel(r.getMaxUid(), r.getMaxIid(),
                          0.0002, train, 1000, 25, r.numberOfTransactions)
    import numpy as np
    np.savez_compressed(
        "SVDModelFile", W=W, H=H)
    # modelf = np.load("BPRMFModelFile" + ".npz")
    # W = modelf['W']
    # H = modelf['H']
    # modelf.close

    from util import test
    t = test.MFtest(W, H, train)
    test.hitrate(test1, t.getRec, 10)
Example #3
0
def mf():
    from util import reader
    r = reader.tabSepReader("u.data")

    from util import split
    train, test1 = split.split(r.getR(), 1234567890)

    from recommender import mf
    W, H = mf.learnModel(r.getMaxUid(), r.getMaxIid(), 0.01, 0.01, 0.01,
                         0.1, train, 150, 3, r.numberOfTransactions,
                         mf.logLoss, mf.dLogLoss)
    import numpy as np
    # np.savez_compressed(
    #    "BPRMFModelFile", W=W, H=H)
    # modelf = np.load("BPRMFModelFile" + ".npz")
    # W = modelf['W']
    # H = modelf['H']
    # modelf.close

    from util import test
    t = test.MFtest(W, H, train)
    test.hitrate(test1, t.getRec, 10)
Example #4
0
def fastBPRMF():
    from util import reader
    r = reader.fastStringSepReader("u.data", "\t")

    from util import split
    train, test1 = split.split(r.getR(), 1234567890)

    from recommender import fastBPRMF
    W, H = fastBPRMF.learnModel(r.getMaxUid(), r.getMaxIid(), 0.01, 0.01, 0.01,
                         0.1, train, 150, 3)
    import numpy as np
    # np.savez_compressed(
    #    "BPRMFModelFile", W=W, H=H)
    # modelf = np.load("BPRMFModelFile" + ".npz")
    # W = modelf['W']
    # H = modelf['H']
    # modelf.close

    from recommender import mf
    from util import test
    t = mf.MFrec(W, H, train)
    test.hitrate(test1, t.getRec, 10)