def get_reco(nfile, user, amount = 10) : m = np.genfromtxt("ml-100k/u.item", dtype=[('myint','i8'),('mystring','S100')], delimiter = "|") ##### x,y = mmat.load_decomposition(nfile) w = y.shape[1] h = x.shape[0] res = [] #Parcours des films for i in xrange(w) : res += [ (i+1, mmat.approx(x,y, user-1, i) ) ] dtype = [('id', int),('rating', float) ] res = np.array(res, dtype = dtype) res = np.sort(res, order='rating') ########## reco = [] for i in xrange(amount) : reco += [ m[ (res[len(res) - i - 1])[0] +1][1] ] return np.array(reco)
def mae(mat_test, X, Y) : H,L = mat_test.shape line = [ np.abs(mat_test[i,j] - mmat.approx(X,Y,i,j)) for i in xrange(H) for j in xrange(L) if mat_test[i,j] <> 0 ] return np.mean(line)
def f4(files): # Temps de prédiction """ Permet de calculer le tps de prédiction moyen """ tps = [] for f in files: x, y = mmat.load_decomposition(f) t1 = time.clock() for i in xrange(100): for j in xrange(100): mmat.approx(x, y, i, j) t2 = time.clock() tps += [t2 - t1] print tps return tps