def readDBandSplit(dbfile): r = reader.tabSepReader(dbfile) fulltrain, testDict = split.split( r.getR(), SEED1) trainingDict, evalDict = split.split( fulltrain, SEED2) output = open("splits.npz", "wb") cPickle.dump(r, output, -1) cPickle.dump(trainingDict, output, -1) cPickle.dump(fulltrain, output, -1) cPickle.dump(testDict, output, -1) cPickle.dump(evalDict, output, -1) output.close() return r, trainingDict, fulltrain, testDict, evalDict
# Reading a database file called "u.data" import reader r = reader.tabSepReader("u.data") # Get 10 recommendations with simple algorithms # for userid 201. #import primitive #import external #rand = primitive.randomRec(r.getR()) #getRec = external.getExternalRec(rand.getRec, r) #print getRec(97, 10) # ## Train a MF model. #import mf # #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())