コード例 #1
0
ファイル: testing.py プロジェクト: npkumar/Hybrid-CF
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"))
コード例 #2
0
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"))
コード例 #3
0
ファイル: main_testing.py プロジェクト: npkumar/Hybrid-CF
        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
コード例 #4
0
ファイル: main_testing.py プロジェクト: npkumar/Hybrid-CF
        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
コード例 #5
0
    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()