def dumpPickles(id): """ Persist memory intensive data structures, item similarities. """ print 'Pickle id %s' % (id) foldername = '../kfold_cluster_' + id + '/' print foldername cluster = algorithm.createPrefs(folder=foldername) for c in range(8): prefs = cluster[c] itemsim = algorithm.calculateSimilarItems(prefs, n=50) dumpname = "../pickle/" + id + "/oitemsim_" + str(c) + ".pickle" pickle.dump(itemsim, open(dumpname, "wb"))
def dumpPickles(id): """ Persist memory intensive data structures, item similarities. """ print 'Pickle id %s'%(id) foldername = '../kfold_cluster_' + id + '/' print foldername cluster = algorithm.createPrefs(folder=foldername) for c in range(8): prefs = cluster[c] itemsim = algorithm.calculateSimilarItems(prefs, n=50) dumpname = "../pickle/" +id + "/oitemsim_" + str(c) + ".pickle" pickle.dump(itemsim, open(dumpname, "wb"))
print removed_items print "Length of new_prefs %d"%(len(new_prefs)) print 'Doing CBR...' sparsity.caseone_doFillUsingCBR(new_prefs, deleted_users) print 'Doing Average Filling...' sparsity.caseone_doAverageFilling(new_prefs, deleted_users) #use the original prefs here. print 'Calculating original item similarity...' oitemsim = original.calculateSimilarItems(org_prefs, n=50) #use the modified prefs here. print 'Calculating algorithm item similarity...' itemsim = algorithm.calculateSimilarItems(new_prefs, n=50) print 'Calculating original ranking...' oranking = original.getRecommendedItems(org_prefs, oitemsim,str(user)) print 'Calculating algorithm ranking...' ranking = original.getRecommendedItems(new_prefs,itemsim,str(user)) print 'Calculating MAE for original...' original_MAE.append(calMAE(oranking,str(user))) print 'Calculating MAE for algorithm...' algorithm_MAE.append(calMAE(ranking,str(user))) print original_MAE
print removed_items print "Length of new_prefs %d" % (len(new_prefs)) print 'Doing CBR...' sparsity.caseone_doFillUsingCBR(new_prefs, deleted_users) print 'Doing Average Filling...' sparsity.caseone_doAverageFilling(new_prefs, deleted_users) #use the original prefs here. print 'Calculating original item similarity...' oitemsim = original.calculateSimilarItems(org_prefs, n=50) #use the modified prefs here. print 'Calculating algorithm item similarity...' itemsim = algorithm.calculateSimilarItems(new_prefs, n=50) print 'Calculating original ranking...' oranking = original.getRecommendedItems(org_prefs, oitemsim, str(user)) print 'Calculating algorithm ranking...' ranking = original.getRecommendedItems(new_prefs, itemsim, str(user)) print 'Calculating MAE for original...' original_MAE.append(calMAE(oranking, str(user))) print 'Calculating MAE for algorithm...' algorithm_MAE.append(calMAE(ranking, str(user))) print original_MAE print algorithm_MAE
caMAE = [] for cid in range(8): print "Cluster id: %d" % (cid) if len(colist) != 0 and len(calist) != 0: coMAE.append(sum(colist) / len(colist)) caMAE.append(sum(calist) / len(calist)) else: colist = [] calist = [] clusterPrefs = cluster[cid] istart = time.time() itemsim = algorithm.calculateSimilarItems(clusterPrefs, n=50) istop = time.time() for user in clusterPrefs: #fix missing values if not user: continue print "Cluster: %d User: %s" % (cid, user) rstart = time.time() #ranking = algorithm.getRecommendedItems(testingPrefs, clusterPrefs,itemsim,user) ranking = original.getRecommendedItems(testingPrefs, itemsim, user) rstop = time.time()