Beispiel #1
0
def evaluate_cb_recommender():

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

    lda_path = './lda/'
    corpus = corpora.MmCorpus(lda_path + 'corpus.mm'),
    index = similarities.MatrixSimilarity.load(lda_path + 'index.lda')

    with open(file_name, 'a', 1) as logfile:
        logfile.write(
            "rak, pak, mae, min_overlap, min_sim, K, min_num_of_ratings, min_rank, user_coverage, "
            "movie_coverage\n")

        for K in np.arange(2, 20, 2):
            recommender = ContentBasedRecs()

            er = EvaluationRunner(0, None, recommender, K)

            result = er.calculate(1, 5, number_test_users=-1)

            user_coverage, movie_coverage = RecommenderCoverage(
                recommender).calculate_coverage()
            pak = result['pak']
            mae = result['mae']
            rak = result['rak']
            logfile.write("{}, {}, {}, {}, {}, {}, {}, {}, {}, {}\n".format(
                rak, pak, mae, min_overlap, min_sim, K, min_number_of_ratings,
                min_rank, user_coverage, movie_coverage))
            logfile.flush()
Beispiel #2
0
def recs_cb(request, user_id, num=6):

    sorted_items = ContentBasedRecs().recommend_items(user_id, num)

    data = {'user_id': user_id, 'data': sorted_items}

    return JsonResponse(data, safe=False)
Beispiel #3
0
def similar_content(request, content_id, num=6):
    # lda = models.ldamodel.LdaModel.load('./lda/model.lda')
    #
    # dictionary = corpora.Dictionary.load('./lda/dict.lda')
    #
    # corpus = corpora.MmCorpus('./lda/corpus.mm')
    # content_sims = dict()
    #
    # md = MovieDescriptions.objects.filter(imdb_id=content_id).first()
    #
    #
    # if md is not None:
    #     index = similarities.MatrixSimilarity.load('./lda/index.lda')
    #
    #     lda_vector = lda[corpus[int(md.lda_vector)]]
    #     sims = index[lda_vector]
    #
    #     sorted_sims = sorted(enumerate(sims), key=lambda item: -item[1])[:num]
    #
    #     movies = get_movie_ids(sorted_sims, corpus, dictionary)
    #
    #     for movie in movies:
    #         target = movie['target']
    #         if target in content_sims.keys():
    #             if movie['sim'] > content_sims[target]['sim']:
    #                 content_sims[target] = movie
    #         else:
    #             content_sims[target] = movie

    sorted_items = ContentBasedRecs().recommend_items_from_items([content_id],
                                                                 num)
    data = {'source_id': content_id, 'data': sorted_items}

    return JsonResponse(data, safe=False)
def evaluate_cb_recommender():
    min_sim = 0
    min_num_of_ratings = 0
    min_rank = 0

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

    with open(file_name, 'a', 1) as logfile:
        logfile.write(
            "ar, map, mae, k, min_sim, min_num_of_ratings, min_rank\n")

        for k in np.arange(5, 20, 3):
            recommender = ContentBasedRecs()

            er = EvaluationRunner(0, None, recommender, k)

            result = er.calculate(10, 5, number_test_users=-1)

            map = result['map']
            mae = result['mae']
            ar = result['ar']
            logfile.write("{}, {}, {}, {}, {}, {}\n".format(
                ar, map, mae, k, min_sim, min_num_of_ratings, min_rank))
            logfile.flush()
Beispiel #5
0
def evaluate_cb_recommender(coverage=False):

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

    with open(file_name, 'a', 1) as logfile:
        logfile.write(
            "ar, map, mae, min_overlap, min_sim, K, min_num_of_ratings, min_rank, user_coverage, "
            "movie_coverage\n")

        for k in np.arange(5, 20, 3):
            recommender = ContentBasedRecs()

            er = EvaluationRunner(0, None, recommender, k)

            result = er.calculate(10, 5, number_test_users=-1)

            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()
Beispiel #6
0
    def __init__(self):
        self.cb = ContentBasedRecs()
        self.cf = NeighborhoodBasedRecs()

        self.wcb1 = Decimal(0.65221204)
        self.wcb2 = Decimal(-0.14638855)
        self.wcf1 = Decimal(-0.0062952)
        self.wcf2 = Decimal(0.09139193)
Beispiel #7
0
def similar_content(request, content_id, num=6):

    sorted_items = ContentBasedRecs().seeded_rec([content_id], num)
    data = {
        'source_id': content_id,
        'data': sorted_items
    }

    return JsonResponse(data, safe=False)
Beispiel #8
0
def recs_cb(request, user_id, num=6):
    start_time = datetime.now()

    print(f"lda loaded in {datetime.now()-start_time}")
    sorted_items = ContentBasedRecs().recommend_items(user_id, num)

    data = {'user_id': user_id, 'data': sorted_items}

    return JsonResponse(data, safe=False)
Beispiel #9
0
 def __init__(self, data_size=1000):
     self.logger = logging.getLogger('FWLS')
     self.train_data = None
     self.test_data = None
     self.rating_count = None
     self.cb = ContentBasedRecs()
     self.cf = NeighborhoodBasedRecs()
     self.fwls = FeatureWeightedLinearStacking()
     self.data_size = data_size
Beispiel #10
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))
Beispiel #11
0
 def __init__(self):
     self.train = None
     self.test = None
     self.rating_count = None
     self.cb = ContentBasedRecs()
     self.cf = NeighborhoodBasedRecs()