Exemplo n.º 1
0
def testMF(W, H, trainingDict, testDict, n):
    t = test.MFtest(W, H, evalDict)
    test.hitrate(testDict, t.getRec, n)
Exemplo n.º 2
0
def constant(r, trainingDict, testDict):
    rec = baselines.constant(trainingDict)
    print("Hitrate for constant: %r" %
          test.hitrate(testDict, rec.getRec, 10))
Exemplo n.º 3
0
def random(r, trainingDict, testDict):
    rec = baselines.randomRec(trainingDict)
    print("Hitrate for random: %r" % test.hitrate(testDict, rec.getRec, 10))
Exemplo n.º 4
0
#
#reg = 0.01  # Regularization constant
#ler = 0.1  # Learning rate
#features = 150  # number of features
#EPOCHS = 3  # number of epochs
#
#W, H = mf.learnModel(
#    r.getMaxUid(), r.getMaxIid(),
#    reg, reg, reg, ler, r.getR(),
#    features, EPOCHS,
#    r.numberOfTransactions,
#    mf.logLoss, mf.dLogLoss)  # With logLoss it will be BPRMF
#
## Get recommendations with a MF model.
#import test
#import external
#t = test.MFtest(W, H, r.getR())
#getRec = external.getExternalRec(t.getRec, r)
#print getRec(97, 10)

# Calculate the hitrate of item based cosine KNN.
import split
splittedMatrix, testDict = split.splitMatrix(r.getMatrix(), 1234567890)

import knn
neighbors = 10  # number of neighbors
k = knn.itemKnn(splittedMatrix, neighbors)

import test
print test.hitrate(testDict, k.getRec, 10)