#epss = params['ALS-WR']['params']['eps'] regs = ["weighted"] lambdas = [0.8] rank = [10] alphas = [10] epss= [100] mus = [0.5] current_perf = dict.fromkeys(['model','reg','lambda','rank','alpha','eps','mu','crossval']) for elt in itertools.product(*[regs,lambdas,rank,alphas,epss,mus,[0]]): reg, l, r, alpha, eps, mu, k = elt current_perf.update({'model':'graphALS','reg':reg,'lambda':l, 'rank':r,'alpha':alpha,'eps':eps,'mu':mu, 'crossval':k}) print(current_perf) bob = graphALS(d=r,num_users=numUser,num_items=numItem,lbda=l,mu=mu, seed=0,reg=reg,verbose=True) t0 = time() bob.fitImplicit(train = data[data['cv']!=k], alpha=alpha, c="log", eps=eps, userGraph = userGraph[['userId','friendId','dot_product_weight']], itemGraph = None, method="svd") T = time()-t0 Rhat = bob.U.dot(bob.V.T) R_test = sparseMatrix(data,k,include=True,names=list(data.columns)[:3]) rank = rankMeasure(R_test,Rhat) print(rank) ind = getLine_fromdict(perf,current_perf) perf.loc[ind] = ['graphALS',reg,l,r,alpha,eps,k,rank,T]
reg, l, r, alpha, eps, mu, k = elt current_perf.update({ 'model': 'graphALS', 'reg': reg, 'lambda': l, 'rank': r, 'alpha': alpha, 'eps': eps, 'mu': mu, 'crossval': k }) print(current_perf) bob = graphALS(d=r, num_users=numUser, num_items=numItem, lbda=l, mu=mu, seed=0, reg=reg, verbose=True) t0 = time() bob.fitImplicit( train=data[data['cv'] != k], alpha=alpha, c="log", eps=eps, userGraph=userGraph[['userId', 'friendId', 'dot_product_weight']], itemGraph=None, method="svd") T = time() - t0 Rhat = bob.U.dot(bob.V.T) R_test = sparseMatrix(data,
# r.extend(list(np.repeat(1.,len(itemIds)*len(itemIds)))) # tmp = np.array([x,y,r]).T # #tmp = pd.DataFrame([x,y,r]).T # tmp = tmp[tmp[:,0]!=tmp[:,1]] # itemContextSparseGraph = np.concatenate((itemContextSparseGraph,tmp.T),axis=1) #============================================================================== current_perf = dict.fromkeys(['model','lambda','rank','crossval']) for elt in itertools.product(*[lambdas,rank,range(K)]): l, r, k = elt current_perf['model'] = 'graphALS' current_perf['lambda'] = l current_perf['rank'] = r current_perf['crossval'] = k print(current_perf) bob = graphALS(d=r,num_users=numUser,num_items=numItem,lbda=l, solve='jacobi',verbose=True) t0 = time() bob.fit(train = data[data['cv']!=k], userGraph = userContextSparseGraph, itemGraph = itemContextSparseGraph) T = time()-t0 Rhat = bob.U.dot(bob.V.T) R_test = sparseMatrix(data,k,include=True) W = R_test.nonzero() rmse = RMSE(R_test,Rhat) print(rmse) ind = getLine_fromdict(perf,current_perf) perf.loc[ind,['model','rank','lambda','crossval','rmse','runningTime']] = ['graphALS',r,l,k,rmse,T] print('-'*50) #==============================================================================