Пример #1
0
def showResult():
  """Get final result from getResultOfArimaMethod()
  and then plot it using pyplot.
  Input:
    None.
  Output:
    None.
  """
  logging.info('I am in showResult......')
  result = getResultOfArimaMethod() # get the result
  length = range(5,51,5)
  #plt imgs of result
  for index in range(5):
    indexName = util.getIndexName(index) # get index name
    plt.figure(index)
    plt.plot(length,result[index])
    plt.title("%s of MTSA with Different Window Sizes of Session" % indexName)
    plt.xlabel("window size of session")
    plt.ylabel(indexName)
    plt.legend()
    plt.savefig("../img/arima_trend_%s.png" % indexName)
    plt.show()
  logging.info('I am out showResult......')
Пример #2
0
def showResult():
  """Using pyplot to plot the experiment results.
     Input:
       None.
     Output:
       None.
  """
  logging.info('I am in showResult......')
  filename = "../txt/%s_testall_%d_%d.txt" % (const.DATASET_NAME,const.TOPIC_NUM,const.TOP_N)
  x = range(1,const.TOP_N,1)
  result = [[[] for i in range(5)] for i in range(3)]
  #read result from file to result
  if os.path.exists(filename):
    print '%s is existing......' % filename    
    rFile = open(filename,"r")
    lines = rFile.readlines()
    for line in lines:
      line = line.rstrip('\n')
      items = line.split("INFO:")
      line = items[1]
      items = line.split(":")
      ids = items[0]
      values = items[1]
      idItems = ids.split(">")
      mid = int(idItems[0])
      topN = int(idItems[1])
      valueItems = values.split()
      result[mid][0].append(float(valueItems[0]))
      result[mid][1].append(float(valueItems[1]))
      result[mid][2].append(float(valueItems[2]))
      result[mid][3].append(float(valueItems[3]))
      result[mid][4].append(float(valueItems[4]))
    rFile.close()
  else:
    rFile = open(filename,"w")
    rFile.close()
  #if some method is not in file, recreate it
  for mid in range(3):
    if len(result[mid][0]) == 0:
      recalls,precisions,f1s,maes,rmses = getErrorOfRecMethod(mid)
      result[mid][0] = recalls
      result[mid][1] = precisions
      result[mid][2] = f1s
      result[mid][3] = maes
      result[mid][4] = rmses

  #plt img of comparing with pure method
  for index in range(5):
    plt.figure(index)
    indexName = util.getIndexName(index)
    mids = [const.ARIMA,const.SIMILAR,const.AVG]
    marker = ['k','k-.','k:']
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[20:],result[mid][index][20:],marker[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],marker[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Algorithms" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/pure_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
    #plt.show()
  logging.info('I am out showResult......')
Пример #3
0
def showResult():
  """Using pyplot to plot the experiment results.
     Input:
       None.
     Output:
       None.
  """
  logging.info('I am in showResult......')
  filename = "../txt/%s_testall_%d_%d.txt" % (const.DATASET_NAME,const.TOPIC_NUM,const.TOP_N)
  x = range(1,const.TOP_N,1)
  result = [[[] for i in range(5)] for i in range(const.METHOD_SIZE)]
  #read result from file to result
  if os.path.exists(filename):
    print '%s is existing......' % filename    
    rFile = open(filename,"r")
    lines = rFile.readlines()
    for line in lines:
      line = line.rstrip('\n')
      items = line.split("INFO:")
      line = items[1]
      items = line.split(":")
      ids = items[0]
      values = items[1]
      idItems = ids.split(">")
      mid = int(idItems[0])
      topN = int(idItems[1])
      valueItems = values.split()
      result[mid][0].append(float(valueItems[0]))
      result[mid][1].append(float(valueItems[1]))
      result[mid][2].append(float(valueItems[2]))
      result[mid][3].append(float(valueItems[3]))
      result[mid][4].append(float(valueItems[4]))
    rFile.close()
  else:
    rFile = open(filename,"w")
    rFile.close()
  #if some method is not in file, recreate it
  for mid in range(const.METHOD_SIZE):
    if len(result[mid][0]) == 0:
      recalls,precisions,f1s,maes,rmses = getErrorOfRecMethod(mid)
      result[mid][0] = recalls
      result[mid][1] = precisions
      result[mid][2] = f1s
      result[mid][3] = maes
      result[mid][4] = rmses

  #plt img of comparing with pure method
  for index in range(5):
    plt.figure(index)
    indexName = util.getIndexName(index)
    mids = [const.ARIMA,const.SIMILAR,const.AVG]
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[10:],result[mid][index][10:],const.marker[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],const.marker[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Algorithms(Pure)" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/pure_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
    #plt.show()

  #plt img of comparing with hybrid method
  for index in range(5):
    plt.figure(index+5)
    indexName = util.getIndexName(index)
    mids = [const.ARIMA,const.ARIMA_SIMILAR,const.ARIMA_AVG,const.ALL_HYBRID]
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[10:],result[mid][index][10:],const.marker[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],const.marker[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Algorithms(Hybrid)" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/hybrid_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
    #plt.show()


  #plt img of comparing with sequential method
  for index in range(5):
    plt.figure(index+10)
    indexName = util.getIndexName(index)
    mids = [const.ARIMA,const.KNN,const.PATTERN,const.MARKOV,const.MARKOV_3]
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[10:],result[mid][index][10:],const.marker[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],const.marker[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Methods" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/seq_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
    #plt.show()
  
  plt.figure(30)
  plt.plot(x,result[const.ARIMA_SIMILAR][3],'k-.',label=util.getMethodName(const.ARIMA_SIMILAR)) 
  plt.plot(x,result[const.ARIMA_AVG][3],'k+',label=util.getMethodName(const.ARIMA_AVG)) 
  plt.plot(x,result[const.ALL_HYBRID][3],'k',label=util.getMethodName(const.ALL_HYBRID)) 
  plt.title("MAE of Hybrid Music Recommendation Methods")
  plt.xlabel("Number of recommendations")
  plt.ylabel("MAE")
  plt.legend()
  plt.xlim(1,160)
  plt.savefig("../img/local_global_%s_%s_%d_%d.png" % (const.DATASET_NAME,"MAE",const.TOPIC_NUM,const.TOP_N))

  plt.figure(31)
  plt.plot(x,result[const.ARIMA_SIMILAR][4],'k-.',label=util.getMethodName(const.ARIMA_SIMILAR)) 
  plt.plot(x,result[const.ARIMA_AVG][4],'k+',label=util.getMethodName(const.ARIMA_AVG)) 
  plt.plot(x,result[const.ALL_HYBRID][4],'k',label=util.getMethodName(const.ALL_HYBRID)) 
  plt.title("RMSE of Hybrid Music Recommendation Methods")
  plt.xlabel("Number of recommendations")
  plt.ylabel("RMSE")
  plt.legend()
  plt.xlim(1,160)
  plt.savefig("../img/local_global_%s_%s_%d_%d.png" % (const.DATASET_NAME,"RMSE",const.TOPIC_NUM,const.TOP_N))

  plt.figure(19)
  improvement = []
  for i in range(len(result[const.ARIMA][1])):
    improvement.append((result[const.ARIMA][1][i]-result[const.KNN][1][i]) / result[const.KNN][1][i])
  plt.plot(x[10:],improvement[10:],'k',label='Improvement over UserKNN Recommender')
  plt.title('Average Precision Improvement over UserKNN Recommender')
  plt.xlabel('Number of recommendations')
  plt.ylabel('Improvement in Average Precision (times)')
  plt.legend()
  indexName = util.getIndexName(1)
  plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))

  plt.figure(20)
  improvement = []
  for i in range(len(result[const.ARIMA][1])):
    improvement.append((result[const.ARIMA][1][i]-result[const.KNN][1][i]) / result[const.KNN][1][i])
  plt.plot(x[10:],improvement[10:],'k',label='Improvement over UserKNN Recommender')
  plt.title('Average Precision Improvement over UserKNN Recommender')
  plt.xlabel('Number of recommendations')
  plt.ylabel('Improvement in Average Precision (times)')
  plt.legend()
  indexName = util.getIndexName(1)
  plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))

  plt.figure(21)
  improvement = []
  for i in range(len(result[const.ARIMA][2])):
    improvement.append((result[const.ARIMA][2][i]-result[const.KNN][2][i]) / result[const.KNN][2][i])
  plt.plot(x[10:],improvement[10:],'k',label='Improvement over UserKNN Recommender')
  plt.title('Average F1-Score Improvement over UserKNN Recommender')
  plt.xlabel('Number of recommendations')
  plt.ylabel('Improvement in Average F1-Score (times)')
  plt.legend()
  indexName = util.getIndexName(2)
  plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
  #plt.show()
  logging.info('I am out showResult......')

  #plt img of comparing with pure method
  for index in range(5):
    plt.figure(index+50)
    indexName = util.getIndexName(index)
    print indexName
    mids = [const.ARIMA,const.SIMILAR,const.KNN,const.AVG,const.PATTERN,const.MARKOV]
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[10:],result[mid][index][10:],const.marker1[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],const.marker1[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Algorithms" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/all_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))

  #plt img of comparing with hybrid method
  for index in range(5):
    plt.figure(index+75)
    indexName = util.getIndexName(index)
    mids = [const.ARIMA,const.ALL_HYBRID]
    markerIndex = 0
    for mid in mids:
      if index == 1 or index == 2:
        plt.plot(x[10:],result[mid][index][10:],const.marker[markerIndex],label=util.getMethodName(mid))
      else:
        plt.plot(x,result[mid][index],const.marker[markerIndex],label=util.getMethodName(mid))
      markerIndex += 1
    plt.title("%s of Different Recommend Algorithms" % indexName)
    plt.xlabel("Number of recommendations")
    plt.ylabel(indexName)
    plt.legend()
    plt.xlim(1,160)
    plt.savefig("../img/hybrid_only_%s_%s_%d_%d.png" % (const.DATASET_NAME,indexName,const.TOPIC_NUM,const.TOP_N))
Пример #4
0
def showResult():
    """Using pyplot to plot the experiment results.
     Input:
       None.
     Output:
       None.
  """
    logging.info('I am in showResult......')
    filename = "../txt/%s_testall_%d_%d.txt" % (const.DATASET_NAME,
                                                const.TOPIC_NUM, const.TOP_N)
    x = range(1, const.TOP_N, 1)
    result = [[[] for i in range(5)] for i in range(const.METHOD_SIZE)]
    #read result from file to result
    if os.path.exists(filename):
        print '%s is existing......' % filename
        rFile = open(filename, "r")
        lines = rFile.readlines()
        for line in lines:
            line = line.rstrip('\n')
            items = line.split("INFO:")
            line = items[1]
            items = line.split(":")
            ids = items[0]
            values = items[1]
            idItems = ids.split(">")
            mid = int(idItems[0])
            topN = int(idItems[1])
            valueItems = values.split()
            result[mid][0].append(float(valueItems[0]))
            result[mid][1].append(float(valueItems[1]))
            result[mid][2].append(float(valueItems[2]))
            result[mid][3].append(float(valueItems[3]))
            result[mid][4].append(float(valueItems[4]))
        rFile.close()
    else:
        rFile = open(filename, "w")
        rFile.close()
    #if some method is not in file, recreate it
    for mid in range(const.METHOD_SIZE):
        if len(result[mid][0]) == 0:
            recalls, precisions, f1s, maes, rmses = getErrorOfRecMethod(mid)
            result[mid][0] = recalls
            result[mid][1] = precisions
            result[mid][2] = f1s
            result[mid][3] = maes
            result[mid][4] = rmses

    #plt img of comparing with pure method
    for index in range(5):
        plt.figure(index)
        indexName = util.getIndexName(index)
        mids = [const.ARIMA, const.SIMILAR, const.AVG]
        markerIndex = 0
        for mid in mids:
            if index == 1 or index == 2:
                plt.plot(x[10:],
                         result[mid][index][10:],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            else:
                plt.plot(x,
                         result[mid][index],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            markerIndex += 1
        plt.title("%s of Different Recommend Algorithms(Pure)" % indexName)
        plt.xlabel("Number of recommendations")
        plt.ylabel(indexName)
        plt.legend()
        plt.xlim(1, 160)
        plt.savefig(
            "../img/pure_%s_%s_%d_%d.png" %
            (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))
        #plt.show()

    #plt img of comparing with hybrid method
    for index in range(5):
        plt.figure(index + 5)
        indexName = util.getIndexName(index)
        mids = [
            const.ARIMA, const.ARIMA_SIMILAR, const.ARIMA_AVG, const.ALL_HYBRID
        ]
        markerIndex = 0
        for mid in mids:
            if index == 1 or index == 2:
                plt.plot(x[10:],
                         result[mid][index][10:],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            else:
                plt.plot(x,
                         result[mid][index],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            markerIndex += 1
        plt.title("%s of Different Recommend Algorithms(Hybrid)" % indexName)
        plt.xlabel("Number of recommendations")
        plt.ylabel(indexName)
        plt.legend()
        plt.xlim(1, 160)
        plt.savefig(
            "../img/hybrid_%s_%s_%d_%d.png" %
            (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))
        #plt.show()

    #plt img of comparing with sequential method
    for index in range(5):
        plt.figure(index + 10)
        indexName = util.getIndexName(index)
        mids = [
            const.ARIMA, const.KNN, const.PATTERN, const.MARKOV, const.MARKOV_3
        ]
        markerIndex = 0
        for mid in mids:
            if index == 1 or index == 2:
                plt.plot(x[10:],
                         result[mid][index][10:],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            else:
                plt.plot(x,
                         result[mid][index],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            markerIndex += 1
        plt.title("%s of Different Recommend Methods" % indexName)
        plt.xlabel("Number of recommendations")
        plt.ylabel(indexName)
        plt.legend()
        plt.xlim(1, 160)
        plt.savefig(
            "../img/seq_%s_%s_%d_%d.png" %
            (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))
        #plt.show()

    plt.figure(30)
    plt.plot(x,
             result[const.ARIMA_SIMILAR][3],
             'k-.',
             label=util.getMethodName(const.ARIMA_SIMILAR))
    plt.plot(x,
             result[const.ARIMA_AVG][3],
             'k+',
             label=util.getMethodName(const.ARIMA_AVG))
    plt.plot(x,
             result[const.ALL_HYBRID][3],
             'k',
             label=util.getMethodName(const.ALL_HYBRID))
    plt.title("MAE of Hybrid Music Recommendation Methods")
    plt.xlabel("Number of recommendations")
    plt.ylabel("MAE")
    plt.legend()
    plt.xlim(1, 160)
    plt.savefig("../img/local_global_%s_%s_%d_%d.png" %
                (const.DATASET_NAME, "MAE", const.TOPIC_NUM, const.TOP_N))

    plt.figure(31)
    plt.plot(x,
             result[const.ARIMA_SIMILAR][4],
             'k-.',
             label=util.getMethodName(const.ARIMA_SIMILAR))
    plt.plot(x,
             result[const.ARIMA_AVG][4],
             'k+',
             label=util.getMethodName(const.ARIMA_AVG))
    plt.plot(x,
             result[const.ALL_HYBRID][4],
             'k',
             label=util.getMethodName(const.ALL_HYBRID))
    plt.title("RMSE of Hybrid Music Recommendation Methods")
    plt.xlabel("Number of recommendations")
    plt.ylabel("RMSE")
    plt.legend()
    plt.xlim(1, 160)
    plt.savefig("../img/local_global_%s_%s_%d_%d.png" %
                (const.DATASET_NAME, "RMSE", const.TOPIC_NUM, const.TOP_N))

    plt.figure(19)
    improvement = []
    for i in range(len(result[const.ARIMA][1])):
        improvement.append(
            (result[const.ARIMA][1][i] - result[const.KNN][1][i]) /
            result[const.KNN][1][i])
    plt.plot(x[10:],
             improvement[10:],
             'k',
             label='Improvement over UserKNN Recommender')
    plt.title('Average Precision Improvement over UserKNN Recommender')
    plt.xlabel('Number of recommendations')
    plt.ylabel('Improvement in Average Precision (times)')
    plt.legend()
    indexName = util.getIndexName(1)
    plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" %
                (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))

    plt.figure(20)
    improvement = []
    for i in range(len(result[const.ARIMA][1])):
        improvement.append(
            (result[const.ARIMA][1][i] - result[const.KNN][1][i]) /
            result[const.KNN][1][i])
    plt.plot(x[10:],
             improvement[10:],
             'k',
             label='Improvement over UserKNN Recommender')
    plt.title('Average Precision Improvement over UserKNN Recommender')
    plt.xlabel('Number of recommendations')
    plt.ylabel('Improvement in Average Precision (times)')
    plt.legend()
    indexName = util.getIndexName(1)
    plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" %
                (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))

    plt.figure(21)
    improvement = []
    for i in range(len(result[const.ARIMA][2])):
        improvement.append(
            (result[const.ARIMA][2][i] - result[const.KNN][2][i]) /
            result[const.KNN][2][i])
    plt.plot(x[10:],
             improvement[10:],
             'k',
             label='Improvement over UserKNN Recommender')
    plt.title('Average F1-Score Improvement over UserKNN Recommender')
    plt.xlabel('Number of recommendations')
    plt.ylabel('Improvement in Average F1-Score (times)')
    plt.legend()
    indexName = util.getIndexName(2)
    plt.savefig("../img/improvement_knn_%s_%s_%d_%d.png" %
                (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))
    #plt.show()
    logging.info('I am out showResult......')

    #plt img of comparing with pure method
    for index in range(5):
        plt.figure(index + 50)
        indexName = util.getIndexName(index)
        print indexName
        mids = [
            const.ARIMA, const.SIMILAR, const.KNN, const.AVG, const.PATTERN,
            const.MARKOV
        ]
        markerIndex = 0
        for mid in mids:
            if index == 1 or index == 2:
                plt.plot(x[10:],
                         result[mid][index][10:],
                         const.marker1[markerIndex],
                         label=util.getMethodName(mid))
            else:
                plt.plot(x,
                         result[mid][index],
                         const.marker1[markerIndex],
                         label=util.getMethodName(mid))
            markerIndex += 1
        plt.title("%s of Different Recommend Algorithms" % indexName)
        plt.xlabel("Number of recommendations")
        plt.ylabel(indexName)
        plt.legend()
        plt.xlim(1, 160)
        plt.savefig(
            "../img/all_%s_%s_%d_%d.png" %
            (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))

    #plt img of comparing with hybrid method
    for index in range(5):
        plt.figure(index + 75)
        indexName = util.getIndexName(index)
        mids = [const.ARIMA, const.ALL_HYBRID]
        markerIndex = 0
        for mid in mids:
            if index == 1 or index == 2:
                plt.plot(x[10:],
                         result[mid][index][10:],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            else:
                plt.plot(x,
                         result[mid][index],
                         const.marker[markerIndex],
                         label=util.getMethodName(mid))
            markerIndex += 1
        plt.title("%s of Different Recommend Algorithms" % indexName)
        plt.xlabel("Number of recommendations")
        plt.ylabel(indexName)
        plt.legend()
        plt.xlim(1, 160)
        plt.savefig(
            "../img/hybrid_only_%s_%s_%d_%d.png" %
            (const.DATASET_NAME, indexName, const.TOPIC_NUM, const.TOP_N))