예제 #1
0
def recs_bpr(request, user_id, num=6):
    sorted_items = BPRRecs().recommend_items(user_id, num)

    data = {
        'user_id': user_id,
        'data': sorted_items
    }
    return JsonResponse(data, safe=False)
예제 #2
0
def evaluate_bpr_recommender():
    number_of_factors = 30
    number_of_iterations = 5
    N = 10
    save_path = './models/bpr/'

    timestr = time.strftime("%Y%m%d-%H%M%S")
    file_name = '{}-bpr-k.csv'.format(timestr)

    with open(file_name, 'a', 1) as logfile:
        logfile.write(
            "ar, map, mae, N, error, factors, number_of_iterations\n")

        builder = BayesianPersonalizationRanking(save_path)

        for number_of_factors in np.arange(5, 50, 5):

            recommender = BPRRecs(save_path + 'model/')

            er = EvaluationRunner(0,
                                  builder,
                                  recommender,
                                  N,
                                  params={
                                      'k': number_of_factors,
                                      'num_iterations': number_of_iterations,
                                      'save_path': save_path + 'model/'
                                  })

            result = er.calculate(10, 5)

            map = result['map']
            mae = result['mae']
            ar = result['ar']
            error = builder.error if builder else 0
            logfile.write("{}, {}, {}, {}, {}, {}, {}\n".format(
                ar, map, mae, N, error, number_of_factors,
                number_of_iterations))
            logfile.flush()
예제 #3
0
def evaluate_bpr_recommender(coverage=False):
    save_path = './models/bpr/'

    timestr = time.strftime("%Y%m%d-%H%M%S")
    file_name = '{}-bpr-k.csv'.format(timestr)

    with open(file_name, 'a', 1) as logfile:
        logfile.write("rak,pak,mae,k,user_coverage,movie_coverage\n")
        builder = BayesianPersonalizationRanking(save_path)
        for k in np.arange(0, 20, 2):

            recommender = BPRRecs()

            er = EvaluationRunner(0,
                                  builder,
                                  recommender,
                                  k,
                                  params={
                                      'k': 10,
                                      'num_iterations': 20,
                                      'save_path': save_path + 'model/'
                                  })

            result = er.calculate(1, 5)
            builder = None
            user_coverage, movie_coverage = 0, 0
            if coverage:
                user_coverage, movie_coverage = RecommenderCoverage(
                    recommender).calculate_coverage(k)

            map = result['map']
            mae = result['mae']
            ar = result['ar']
            logfile.write("{}, {}, {}, {}, {}, {}\n".format(
                ar, map, mae, k, user_coverage, movie_coverage))
            logfile.flush()
예제 #4
0
    args = parser.parse_args()

    print(args.fwls)
    k = 10
    cov = None
    if args.fwls:
        logger.debug("evaluating coverage of fwls")
        cov = RecommenderCoverage(FeatureWeightedLinearStacking)
        cov.calculate_coverage(K=k, recName='fwls{}'.format(k))

    if args.cf:
        logger.debug("evaluating coverage of cf")
        cov = RecommenderCoverage(NeighborhoodBasedRecs())
        cov.calculate_coverage(K=k, recName='cf{}'.format(k))

    if args.cb:
        logger.debug("evaluating coverage of cb")
        cov = RecommenderCoverage(ContentBasedRecs())
        cov.calculate_coverage(K=k, recName='cb{}'.format(k))

    if args.ltr:
        logger.debug("evaluating coverage of ltr")
        cov = RecommenderCoverage(BPRRecs())
        cov.calculate_coverage(K=k, recName='bpr{}'.format(k))

    if args.funk:
        logger.debug("evaluating coverage of funk")
        cov = RecommenderCoverage(FunkSVDRecs())

        cov.calculate_coverage(K=k, recName='funk{}'.format(k))