Ejemplo n.º 1
0
def worker(fold, n_users, n_items, dataset_dir):
    traFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tra.txt'
    trasR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, traFilePath),
                    binarize_threshold))

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), trasR.shape,
        trasR.nnz, '%.2f' % (trasR.nnz / float(trasR.shape[0])))

    tstFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tst.txt'
    tstsR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, tstFilePath),
                    binarize_threshold))

    sampler = Sampler(trasR, gsize, negSample, batch_size)

    gbprmf = GBPRMF(n_users, n_items, topN, rho, gsize, split_method,
                    eval_metrics, reg, n_factors, batch_size)
    scores = gbprmf.train(fold + 1, trasR, tstsR, sampler)

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), 'gsize=', gsize,
        'rho=', rho, 'reg=', reg)
    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1),
        ','.join(['%s' % eval_metric for eval_metric in eval_metrics]) +
        '@%d=' % (topN) + ','.join(['%.6f' % (score) for score in scores]))

    gbprmf.close()
    return scores
Ejemplo n.º 2
0
def worker(fold, n_users, n_items, dataset_dir):
    traFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tra.txt'
    trasR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, traFilePath),
                    binarize_threshold))

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), trasR.shape,
        trasR.nnz, '%.2f' % (trasR.nnz / float(trasR.shape[0])))

    tstFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tst.txt'
    tstsR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, tstFilePath),
                    binarize_threshold))

    sampler = Sampler(trasR, n_neg=negSample, batch_size=batch_size)

    cml = CML(n_users, n_items, topN, split_method, eval_metrics, reg_cov,
              margin, use_rank_weight, clip_norm, n_factors, batch_size)
    scores = cml.train(fold + 1, trasR, tstsR, sampler)

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1),
        ','.join(['%s' % eval_metric for eval_metric in eval_metrics]) +
        '@%d=' % (topN) + ','.join(['%.6f' % (score) for score in scores]))

    cml.close()

    return scores
def worker(fold, n_users, n_items, dataset_dir):
    traFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tra.txt'
    trasR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, traFilePath),
                    binarize_threshold))

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), trasR.shape,
        trasR.nnz, '%.2f' % (trasR.nnz / float(trasR.shape[0])))

    tstFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tst.txt'
    tstsR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, tstFilePath),
                    binarize_threshold))

    prigp = PRIGP(n_users, n_items, topK, topN, split_method, eval_metrics,
                  alpha, reg, n_factors, batch_size)

    scores = prigp.train(fold + 1, trasR, tstsR)

    print('topK=', topK, 'alpha=', alpha, 'reg=', reg)
    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1),
        ','.join(['%s' % eval_metric for eval_metric in eval_metrics]) +
        '@%d=' % (topN) + ','.join(['%.6f' % (score) for score in scores]))

    prigp.close()

    return scores
def worker(fold, n_users, n_items, dataset_dir):
    traFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tra.txt'
    trasR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, traFilePath),
                    binarize_threshold))

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), trasR.shape,
        trasR.nnz, '%.2f' % (trasR.nnz / float(trasR.shape[0])))

    tstFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tst.txt'
    tstsR = lil_matrix(
        matBinarize(loadSparseR(n_users, n_items, tstFilePath),
                    binarize_threshold))

    uicf = UserItemCF(n_users, n_items, topK, theta, topN, split_method,
                      eval_metrics)
    scores = uicf.train(fold + 1, trasR, tstsR)

    print(
        dataset_dir.split('/')[-2] + '@%d:' % (fold + 1),
        ','.join(['%s' % eval_metric for eval_metric in eval_metrics]) +
        '@%d=' % (topN) + ','.join(['%.6f' % (score) for score in scores]))

    return scores
def worker(fold, n_users, n_items, dataset_dir):
    traFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tra.txt'
    trasR = lil_matrix(matBinarize(loadSparseR(n_users, n_items, traFilePath), binarize_threshold))

    print(dataset_dir.split('/')[-2] + '@%d:' % (fold + 1), trasR.shape, trasR.nnz,
          '%.2f' % (trasR.nnz / float(trasR.shape[0])))

    tstFilePath = dataset_dir + 'ratings__' + str(fold + 1) + '_tst.txt'
    tstsR = lil_matrix(matBinarize(loadSparseR(n_users, n_items, tstFilePath), binarize_threshold))

    sampler = Sampler(trasR, negRatio, batch_size)
    wrmf = WRMF(n_users, n_items, topN, split_method, eval_metrics, weight, reg, n_factors, batch_size)
    scores = wrmf.train(fold+1, trasR, tstsR, sampler)

    print(dataset_dir.split('/')[-2] + '@%d:' % (fold + 1),'weight=',weight,'reg=',reg)
    print('fold=%d:' % (fold+1), ','.join(['%s' % eval_metric for eval_metric in eval_metrics]), '=',
          ','.join(['%.6f' % (score) for score in scores]))

    return scores