Beispiel #1
0
rec, neg_u = load_data(daily_dir)
print('before filtering: total counts {}'.format(total_count_ui_pairs(rec)))

rec_filtered = filter_out_negs(rec, neg_u)
print('after filtering:  total counts {}'.format(total_count_ui_pairs(rec_filtered)))

rec_processed = process_rec_single_user_online_round(rec_filtered)

print('after postprocess:  total counts {}'.format(total_count_ui_pairs(rec_processed)))



'''
local evalation part
'''

prep_dir='../examples/preprocessing_cache/'
raw_data='../raw_data/xing/'

if len(sys.argv) >= 3:
  gt_dir = sys.argv[2]

from evaluate import Evaluation
e = Evaluation(prep_dir, raw_data, daily_dir, gt_dir)

scores = e.local_eval_on(rec_processed)
print('scores: {}'.format(scores))


Beispiel #2
0
def compute_scores(raw_data_dir=FLAGS.raw_data, data_dir=FLAGS.data_dir,
                   dataset=FLAGS.dataset, save_recommendation=FLAGS.saverec,
                   train_dir=FLAGS.train_dir, test=FLAGS.test, true_targets=FLAGS.true_targets):

    from evaluate import Evaluation
    from post_processing import filter_out_negs
    e = Evaluation(FLAGS.prep_dir, raw_data_dir, FLAGS.raw_data_daily)

    daily_raw_data_dir=FLAGS.raw_data_daily

    if true_targets:
        if FLAGS.reverse:
            user_file_name = os.path.join(daily_raw_data_dir, 'daily_target_items_list')
        else:
            user_file_name = os.path.join(daily_raw_data_dir, 'daily_target_users_set')
    else:
        if FLAGS.reverse:
            user_file_name = os.path.join(raw_data_dir, 'daily_target_local_list')
        else:
            user_file_name = os.path.join(raw_data_dir, 'target_users_set')
            
        
    if FLAGS.new_users:
        if FLAGS.reverse:
            item_file_name = os.path.join(daily_raw_data_dir, 'daily_target_users_set')
        else:
            item_file_name = os.path.join(daily_raw_data_dir, 'daily_target_items_list')
    else:
        if FLAGS.reverse:
            item_file_name = os.path.join(raw_data_dir, 'target_users_set')
        else:
            item_file_name = os.path.join(raw_data_dir, 'daily_target_local_list')

#     if FLAGS.reverse:
#         target_users = pickle.load(open(user_file_name, 'rb'))
#         t_ids = pickle.load(open(item_file_name, 'rb'))
#     else:
    target_users = pickle.load(open(item_file_name, 'rb'))
    t_ids = pickle.load(open(user_file_name, 'rb'))
        
    #t_ids = pickle.load(open(item_file_name, 'rb'))
    t_ids = list(t_ids)
    target_users = set(target_users)
    print(FLAGS.new_users, FLAGS.true_targets)
    print(len(t_ids),len(target_users))
    if FLAGS.reverse:
        suf = ''
    else:
        suf = '_rev'

    if true_targets and FLAGS.new_users:
        reclogfile = 'online_raw_rec_hmf' + suf
           
    elif not FLAGS.true_targets and not FLAGS.new_users:
        reclogfile = 'local_raw_rec_hmf' + suf

#     if true_targets:
#         reclogfile = "online_raw_rec_hmf"
#         t_ids = pickle.load(open(os.path.join(daily_raw_data_dir, 'daily_target_items_list'), 'rb'))
#         target_users = pickle.load(open(os.path.join(daily_raw_data_dir, 'daily_target_users_set'), 'rb'))
#     else:
#         reclogfile = "local_raw_rec_hmf"
#         t_ids = pickle.load(open(os.path.join(raw_data_dir, 'target_items_local_list'), 'rb'))
#         target_users = pickle.load(open(os.path.join(raw_data_dir, 'target_users_set'), 'rb'))

    R = recommend(t_ids, data_dir=data_dir)
    # rec_save_path = os.path.join(daily_raw_data_dir, reclogfile)
    # R = pickle.load(open(rec_save_path, 'rb'))

    if save_recommendation:
        rec_save_path = os.path.join(daily_raw_data_dir, reclogfile)
        pickle.dump(R, open(rec_save_path, 'wb'))

    # R = filter_recs(R, set(target_users))

    if not FLAGS.reverse:
        print('no post processing is needed. return')
        return
    neg_users_set = pickle.load(open(os.path.join(FLAGS.prep_dir, 'neg_users_set')+suf, 'rb'))

    # e.online_solutions_write(R, daily_raw_data_dir, 'basic_rec_done')
    R_filtered = filter_out_negs(R, neg_users_set)
    # e.online_solutions_write(R_filtered, daily_raw_data_dir, 'fitered_out_negs_done')

    if true_targets:
        # R = process_rec_single_user_online_round(R)
        # e.online_solutions_write(R, daily_raw_data_dir, 'online_submission.txt')
        R_filtered = process_rec_single_user_online_round(R_filtered)
        e.online_solutions_write(R_filtered, daily_raw_data_dir, 'neg_filtered_online_submission' + suf + '.txt')
    else:
        scores = e.local_eval_on(R)
        e.local_write_scores(scores, 'local_eval_scores'+suf+'.txt', train_dir)
        scores_filteredR = e.local_eval_on(R_filtered)
        e.local_write_scores(scores_filteredR, 'neg_filtered_local_eval_scores'+suf+'.txt', train_dir)