Exemple #1
0
 def testTp(self):
     simCalMethod = paper.simPCC
     sparseness = 20
     fileNumbers = 10
     for i in range(1, fileNumbers + 1):
         #文件对象
         print i,
         euiFileName = 'throught/ipcc/euislopeone-%d-%d.txt' % (sparseness,
                                                                i)
         pfEui = open(euiFileName, 'w')
         #load data
         trainFileName = r'throught/training%d-%d.txt' % (sparseness, i)
         trainArrayObj = paper.createArrayObj(trainFileName)
         testFileName = r'throught/test%d-%d.txt' % (sparseness, i)
         testArrayObj = paper.loadTest(testFileName)
         #相似度矩阵数据
         wsSimFileName = 'throught/ipcc/simArrayWs-%d-%d.txt' % (sparseness,
                                                                 i)
         wsSimArrayObj = paper.createSimArray(trainArrayObj.T, simCalMethod)
         paper.save(wsSimArrayObj, wsSimFileName)
         #            wsSimArrayObj = paper.load(wsSimFileName)
         #计算预测准确
         print calMaeAndRmse(trainArrayObj, testArrayObj, wsSimArrayObj,
                             pfEui)
         pfEui.close()
     print 'ok'
Exemple #2
0
 def testTp(self):
     for sparseness in  [5, 10, 15, 20]:
         for i in range(1, fileNumbers+1):
             #文件对象
             print i, 
             euiFileName = 'throught/weightedslopeone/euislopeone-%d-%d.txt' % (sparseness,i)
             pfEui = open(euiFileName, 'w')
             #load data
             trainFileName = r'throught/training%d-%d.txt' % (sparseness, i)
             trainArrayObj = paper.createArrayObj(trainFileName)
             testFileName = r'throught/test%d-%d.txt' % (sparseness, i)
             testArrayObj = paper.loadTest(testFileName)
             #计算预测准确
             print calMaeAndRmse(trainArrayObj, testArrayObj, pfEui) 
             pfEui.close()
         print 'ok'
Exemple #3
0
 def testRt(self):
     sparseness = 5
     fileNumbers = 10
     for i in range(1, fileNumbers + 1):
         #文件对象
         print i,
         euiFileName = 'rt/userMean/euislopeone-%d-%d.txt' % (sparseness, i)
         pfEui = open(euiFileName, 'w')
         #load data
         trainFileName = r'rt/sparseness%d/training%d.txt' % (sparseness, i)
         trainArrayObj = paper.createArrayObj(trainFileName)
         testFileName = r'rt/sparseness%d/test%d.txt' % (sparseness, i)
         testArrayObj = paper.loadTest(testFileName)
         #计算预测准确
         print calMaeAndRmse(trainArrayObj, testArrayObj, pfEui)
         pfEui.close()
     print 'ok'
Exemple #4
0
 def testRt(self):
     for sparseness in [5, 10, 15, 20]:
         for i in range(1, fileNumbers + 1):
             #文件对象
             print i,
             euiFileName = 'rt/mf/euislopeone-%d-%d.txt' % (sparseness, i)
             pfEui = open(euiFileName, 'w')
             #load data
             trainFileName = r'rt/sparseness%d/training%d.txt' % (
                 sparseness, i)
             trainArrayObj = paper.createArrayObj(trainFileName)
             testFileName = r'rt/sparseness%d/test%d.txt' % (sparseness, i)
             testArrayObj = paper.loadTest(testFileName)
             #计算预测准确
             p, q = learningAddIndicateFunctionlfm(trainArrayObj)
             maeAndRmseRt(p, q, testArrayObj, pfEui)
             pfEui.close()
         print 'ok'
Exemple #5
0
 def testTp(self):
     for sparseness in [5, 10, 15, 20]:
         for i in range(1, fileNumbers + 1):
             #文件对象
             print i,
             euiFileName = 'throught/mf/euislopeone-%d-%d.txt' % (
                 sparseness, i)
             pfEui = open(euiFileName, 'w')
             #load data
             trainFileName = r'throught/training%d-%d.txt' % (sparseness, i)
             trainArrayObj = paper.createArrayObj(trainFileName)
             testFileName = r'throught/test%d-%d.txt' % (sparseness, i)
             testArrayObj = paper.loadTest(testFileName)
             #计算预测准确
             trainArrayObj[trainArrayObj != NoneValue] = (
                 trainArrayObj[trainArrayObj != NoneValue] -
                 44.034) / 107.439
             p, q = learningAddIndicateFunctionlfm(trainArrayObj)
             maeAndRmseTp(p, q, testArrayObj, pfEui)
             pfEui.close()
         print 'ok'
Exemple #6
0
def loadDataSet(trainFile, testFile):
    import paper
    trainArray = paper.createArrayObj(trainFile)
    testObj = paper.loadTest(testFile)
    return trainArray, testObj
Exemple #7
0
if __name__ == '__main__':
    simCalMethod = paper.simPCC
    fileNumbers = 10
    for sparseness in [5, 10, 15, 20]:
        #文件对象
        for i in range(1, fileNumbers + 1):
            print i,
            #            euiFileName = 'rt/upcc/euislopeone-%d-%d.txt' % (sparseness,i)
            euiFileName = 'throught/upcc/euislopeone-%d-%d.txt' % (sparseness,
                                                                   i)
            pfEui = open(euiFileName, 'w')
            #load data
            #            trainFileName = r'rt/sparseness%d/training%d.txt' % (sparseness, i)
            #            testFileName = r'rt/sparseness%d/test%d.txt' % (sparseness, i)
            #throught
            trainFileName = r'throught/training%d-%d.txt' % (sparseness, i)
            testFileName = r'throught/test%d-%d.txt' % (sparseness, i)
            trainArrayObj = paper.createArrayObj(trainFileName)
            testArrayObj = paper.loadTest(testFileName)
            #相似度矩阵数据
            #            userSimFileName = 'rt/upcc/simArrayUser-%s-%d.txt' % (sparseness,i)
            userSimFileName = 'throught/upcc/simArrayUser-%s-%d.txt' % (
                sparseness, i)
            userSimArrayObj = paper.createSimArray(trainArrayObj, simCalMethod)
            paper.save(userSimArrayObj, userSimFileName)
            #        userSimArrayObj = paper.load(userSimFileName)
            #计算预测准确
            mae, rmse = calMaeAndRmse()
            print mae, rmse
            pfEui.close()
    print 'ok'