if not len(sys.argv) == 1:
        leave_k_out = int(sys.argv[1])
    print 'Use default leave k out: k=' + str(leave_k_out)

    if not len(sys.argv) <= 2:
        lafactor = int(sys.argv[2])
    print 'Use default latent factor: ' + str(lafactor)

    max_rank = 2000

    # number of repetitions.
    total_iteration = 2

    # recommendation algorithms RandUV(latent_factor=lafactor),
    method_list = [ HierLat(latent_factor=lafactor, cold_start = HierLat.CS_EQUAL_PROB),  \
                    LMaFit(latent_factor=lafactor),  NMF(latent_factor=lafactor),
                    PMF(latent_factor=lafactor),     TriUHV(latent_factor=lafactor)  ]

    # main method.
    result = experiment_coldstart_map(exp_name, daily_data_file, \
                min_occ_user, min_occ_prog, num_user, num_prog,\
                method_list,  leave_k_out, total_iteration, max_rank, binary = False)

    matlab_output = {}
    for method_name, method_iter_perf in result.items():
        print 'Method: ' + method_name
        rmse = sum(x['RMSE'] for x in method_iter_perf) / len(method_iter_perf)
        print '>>Average RMSE      : %.5f' % rmse

        perf_recall = np.zeros(len(method_iter_perf[0]['recall']))
        perf_precision = np.zeros(len(method_iter_perf[0]['precision']))
 
 exp_name = 'test_exp_mid_prec_rec'; # something meaningful. 
 
 # filtering criteria
 min_occ_user = 35;
 min_occ_prog = 300;
 
 top_n = 50; # performance computed on top N; 
 
 leave_k_out = 10; # perform leave k out. 
 
 # number of repetitions. 
 total_iteration = 3;
 
 # recommendation algorithms 
 method_list = [ LMaFit(latent_factor=lafactor), RandUV(latent_factor=lafactor), \
                HierLat(latent_factor=lafactor), NMF(latent_factor=lafactor),
                PMF(latent_factor=lafactor),     TriUHV(latent_factor=lafactor)  ];
 
 # main method. 
 result = experiment_leave_k_out(exp_name, daily_data_file, min_occ_user, min_occ_prog, \
             method_list,  leave_k_out, total_iteration, top_n);
 
 # display results (average RMSE). 
 for method_name, method_iter_perf in result.items():
     print 'Method: '+ method_name;
     print  '>>Average precision : %.5f' % (sum( x['prec']   for x in method_iter_perf)/len(method_iter_perf));
     print  '>>Average recall    : %.5f' % (sum( x['recall'] for x in method_iter_perf)/len(method_iter_perf));
     print  '>>Average rmse      : %.5f' % (sum( x['rmse']   for x in method_iter_perf)/len(method_iter_perf));
     #print method_iter_perf;
 
 
 if not len(sys.argv) == 1:
     leave_k_out = int(sys.argv[1]);
 print 'Use default leave k out: k=' + str(leave_k_out);
 
 if not len(sys.argv) <= 2:
     lafactor = int(sys.argv[2]);
 print 'Use default latent factor: ' + str(lafactor); 
 
 max_rank = 2000;
 
 # number of repetitions. 
 total_iteration = 2;
 
 # recommendation algorithms %RandUV(latent_factor=lafactor),
 method_list = [ LMaFit(latent_factor=lafactor),  item_item_sim(N = lafactor), \
                 HierLat(latent_factor=lafactor), NMF(latent_factor=lafactor),
                 PMF(latent_factor=lafactor),     TriUHV(latent_factor=lafactor)  ];
 
 # main method. 
 result = experiment_leave_k_out_map(exp_name, daily_data_file, \
             min_occ_user, min_occ_prog, num_user, num_prog,\
             method_list,  leave_k_out, total_iteration, max_rank, binary = True);
 
 matlab_output = {};
 for method_name, method_iter_perf in result.items():
     print 'Method: '+ method_name;
     rmse = sum( x['RMSE']   for x in method_iter_perf)/len(method_iter_perf);
     print  '>>Average RMSE      : %.5f' % rmse;
     
     perf_recall = np.zeros(len(method_iter_perf[0]['recall']));
Ejemplo n.º 4
0
    filename = "../../../datasample/agg_duid_pid_watchtime_genre/20131209_100000"

    # load data.
    reader = DailyWatchTimeReader()
    feedback_data = reader.read_file_with_minval(filename, 1, 1)

    # build model with 3 latent factors.
    r = 10
    # the L_2 norm regularizer
    lamb = 0.1
    # the stopping delta value
    delta = 1e-5
    # the maximium iteration number
    maxiter = 100

    LMaFit_model = LMaFit(r, lamb, delta, maxiter, verbose=True)
    LMaFit_model.train(feedback_data)

    # test.
    loc_row = [200, 4, 105]
    loc_col = [10, 22, 4]
    print 'Prediction:'
    print LMaFit_model.predict(loc_row, loc_col)

    # test cold start.
    row = [0, 0, 1, 1, 2, 3, 3]
    col = [0, 3, 1, 4, 0, 1, 3]
    data = [1, 1, 1, 1, 1, 1, 1]

    fbdata = FeedbackData(row, col, data, 4, 5, {}, {}, {})
    LMaFit_model = LMaFit(2, 0.001, 1e-5, 100)
Ejemplo n.º 5
0
 filename = "../../../datasample/agg_duid_pid_watchtime_genre/20131209_100000";
  
 # load data. 
 reader = DailyWatchTimeReader();
 feedback_data = reader.read_file_with_minval(filename, 1, 1);
  
 # build model with 3 latent factors.
 r = 10;
 # the L_2 norm regularizer 
 lamb = 0.1; 
 # the stopping delta value 
 delta = 1e-5;
 # the maximium iteration number
 maxiter = 100;
   
 LMaFit_model = LMaFit(r,lamb,delta,maxiter, verbose = True);
 LMaFit_model.train(feedback_data);
  
 # test. 
 loc_row = [200,   4, 105];
 loc_col = [ 10,  22,   4];
 print 'Prediction:'
 print LMaFit_model.predict(loc_row, loc_col);
 
 
 # test cold start.
 row =  [0, 0, 1, 1, 2, 3, 3];
 col =  [0, 3, 1, 4, 0, 1, 3];
 data = [1, 1, 1, 1, 1, 1, 1];
  
 fbdata = FeedbackData(row, col, data, 4, 5, {}, {}, {}); 
Ejemplo n.º 6
0
    # filtering criteria
    min_occ_user = 35
    min_occ_prog = 300

    # specify the percentage of training and (1 - training_prec) is testing.
    training_prec = 0.5

    # number of repetitions.
    total_iteration = 5

    # latent factor
    lf = 10

    # recommendation algorithms
    method_list = [
        LMaFit(latent_factor=lf),
        RandUV(latent_factor=lf),
        HierLat(latent_factor=lf)
    ]

    # main method.
    result = experiment_rand_split(exp_name, daily_data_file, min_occ_user, min_occ_prog, \
                method_list,  training_prec, total_iteration)

    # display results (average RMSE).
    for method_name, method_iter_perf in result.items():
        print 'Method: ' + method_name
        print '>>Average performance RMSE: %.5f' % (
            sum(x for x in method_iter_perf) / len(method_iter_perf))

    #print result;
Ejemplo n.º 7
0
    exp_name = 'test_exp'
    # something meaningful.

    # filtering criteria
    min_occ_user = 4
    min_occ_prog = 1

    # specify the percentage of training and (1 - training_prec) is testing.
    training_prec = 0.5

    # number of repetitions.
    total_iteration = 3

    # recommendation algorithms
    method_list = [
        LMaFit(latent_factor=2),
        RandUV(latent_factor=2),
        HierLat(latent_factor=2)
    ]

    # main method.
    result = experiment_rand_split(exp_name, daily_data_file, min_occ_user, min_occ_prog, \
                method_list,  training_prec, total_iteration)

    # display results (average RMSE).
    for method_name, method_iter_perf in result.items():
        print 'Method: ' + method_name
        print '>>Average performance RMSE: %.5f' % (
            sum(x for x in method_iter_perf) / len(method_iter_perf))

    #print result;