def getErrorOfRecMethod(recType = 0): """Get error of all recommender. Input: recType - id of recommender. Output: recalls,precisions,f1s,maes,rmses. """ start_time = time.time() songDict = persist.readSongFromFile() allPlaylist = persist.readPlaylistFromFile_Session() recalls = [] precisions = [] f1s = [] maes = [] rmses = [] for scale in range(10): playlistDict = allPlaylist[scale] if recType == const.ARIMA: recDict = predict.getRecDict(playlistDict,songDict,recType,scale) elif recType == const.SIMILAR: recDict = predict.getRecDict(playlistDict,songDict,recType,scale) elif recType == const.AVG: recDict = predict.getRecDict(playlistDict,songDict,recType,scale) index = 0 for topN in range(1,const.TOP_N,1): recall,precision,f1 = util.getTopNIndex(recDict,playlistDict,topN) mae,rmse = util.getMAEandRMSE(recDict,playlistDict,songDict,topN) if scale == 0: recalls.append(recall) precisions.append(precision) f1s.append(f1) maes.append(mae) rmses.append(rmse) else: recalls[index] += recall precisions[index] += precision f1s[index] += f1 maes[index] += mae rmses[index] += rmse index += 1 #cal the avg value recalls = [recall / 10 for recall in recalls] precisions = [precision / 10 for precision in precisions] f1s = [f1 / 10 for f1 in f1s] maes = [mae / 10 for mae in maes] rmses = [rmse / 10 for rmse in rmses] #logging info to log index = 0 for topN in range(1,const.TOP_N,1): print '%d:TopN = %d:%f %f %f %f %f' % (recType,topN,recalls[index],precisions[index],f1s[index],maes[index],rmses[index]) logging.info('%d>%d:%f %f %f %f %f' % (recType,topN,recalls[index],precisions[index],f1s[index],maes[index],rmses[index])) index += 1 end_time = time.time() print 'Consumed:%d' % (end_time-start_time) return recalls,precisions,f1s,maes,rmses
def getErrorOfRecMethod(recType = 0): """Get error of different recommemenders. Input: recType - type of recommender. Output: recalls - all hit ratios. """ start_time = time.time() if recType == 0: songMap = getVSMSpace() elif recType == 1: songMap = getTF_IDFSpace() elif recType == 2: songMap = getLSASpace() elif recType == 3: songMap = getLDASpace() allPlaylist = persist.readPlaylistFromFile_Session() recalls = [] for scale in range(10): playlistDict = allPlaylist[scale] recDict = getRecDict(playlistDict,songMap,scale,recType) index = 0 for topN in range(1,const.TOP_N,1): recall = hitRatio(recDict,playlistDict,topN) if scale == 0: recalls.append(recall) else: recalls[index] += recall index += 1 #cal the avg value recalls = [recall / 10.0 for recall in recalls] #logging info to log index = 0 for topN in range(1,const.TOP_N,1): print '%d:TopN = %d:%f' % (recType,topN,recalls[index]) logging.info('%d>%d:%f' % (recType,topN,recalls[index])) index += 1 end_time = time.time() print 'Consumed:%d' % (end_time-start_time) return recalls