예제 #1
0
def main(train_file, test_file):
    A = tsv_to_matrix(train_file)

    W = slim_train(A)

    recommendations = slim_recommender(A, W)

    compute_precision(recommendations, test_file)
예제 #2
0
def main(train_file, test_file):
    A = tsv_to_matrix(train_file)

    W = slim_train(A)

    recommendations = slim_recommender(A, W)

    compute_precision_as_an_oracle(recommendations, test_file)
예제 #3
0
파일: glslimr0.py 프로젝트: yedongyu/RS
def main(train_file, part_file, test_file):

    AG = tsv_to_matrix(train_file, 942, 1682)
    AP = tsv_to_matrix(part_file, 942, 1682)

    W1 = slim_train(AG)
    W2 = slim_train(AP)
    for i in range(0, 11):
        W = (i / 10) * W1 + (1 - i / 10) * W2
        print(i / 10)
        recommendations = slim_recommender(AP, W)
        compute_precision(recommendations, test_file)
예제 #4
0
def main(train_file, part_file):

    AG = tsv_to_matrix(train_file, 942, 1682)
    AP = tsv_to_matrix(part_file, 942, 1682)

    W1 = slim_train(AG)
    W2 = slim_train(AP)

    W = 0 * W1 + 1 * W2

    recommendations = slim_recommender(AP, W)

    compute_precision(recommendations, part_file)
예제 #5
0
def main(train_file, user_sideinformation_file, test_file):
    A = tsv_to_matrix(train_file)
    B = tsv_to_matrix(user_sideinformation_file)
    """
    from util import mm2csr
    mm2csr(A, '/tmp/train.mat')
    mm2csr(useritem_featureitem, '/tmp/train_feature.mat')
    C = tsv_to_matrix(test_file)
    mm2csr(C, '/tmp/test.mat')
    """

    W = sslim_train(A, B)

    recommendations = slim_recommender(A, W)

    compute_precision(recommendations, test_file)
예제 #6
0
파일: sslim.py 프로젝트: LZChuan/toyslim
def main(train_file, user_sideinformation_file, test_file):
    A = tsv_to_matrix(train_file)
    B = tsv_to_matrix(user_sideinformation_file)

    """
    from util import mm2csr
    mm2csr(A, '/tmp/train.mat')
    mm2csr(useritem_featureitem, '/tmp/train_feature.mat')
    C = tsv_to_matrix(test_file)
    mm2csr(C, '/tmp/test.mat')
    """

    W = sslim_train(A, B)

    recommendations = slim_recommender(A, W)

    compute_precision(recommendations, test_file)
예제 #7
0
파일: hslim.py 프로젝트: ysliu307/tuantian
def main(train_file, user_sideinformation_file, hierarchy_file, test_file):
    A = tsv_to_matrix(train_file)
    B = tsv_to_matrix(user_sideinformation_file, A.shape[0], A.shape[1])
    hierarchy = hierarchy_factory(hierarchy_file)

    # Learning using SLIM
    # We handle user bias only in B because in B we have explicit evaluations
    K = slim_train(handle_user_bias(B))
    W = slim_train(A)

    Wline = generate_subitem_hierarchy(K, W, hierarchy)
    WlineNorm = normalize_wline(Wline)

    #recommendations = slim_recommender(A, W + 0.2 * WlineNorm)
    import pdb;pdb.set_trace()
    recommendations = slim_recommender(A, WlineNorm)

    # See if the predictor is just of not
    #user_cities = np.array([ map(hierarchy, B[i].nonzero()[0].tolist()) for i in range(B.shape[0]) ])
    #G = tsv_to_matrix(test_file)
    #print 'TEM QUE DAR VAZIO: ', set(G[1].nonzero()[0]) & set(user_cities[1])
    ### ---- FIM REMOVAME

    compute_precision(recommendations, test_file)
예제 #8
0
    Mline = vstack((A, Balpha), format='lil')

    # Fit each column of W separately. We put something in each positions of W
    # to allow us direct indexing of each position in parallel
    total_columns = Mline.shape[1]
    ranges = generate_slices(total_columns)
    separated_tasks = []

    for from_j, to_j in ranges:
        separated_tasks.append([from_j, to_j, Mline, model])

    pool = multiprocessing.Pool()
    pool.map(work, separated_tasks)
    pool.close()
    pool.join()

    return shared_array


W = sslim_train(A, B)

recommendations = slim_recommender(A, W)

compute_precision(recommendations, test_file)

"""
main('data/atracoes/10/usuarios_atracoes_train.tsv',
     'data/atracoes/10/palavras_atracoes.tsv',
     'data/atracoes/10/usuarios_atracoes_test.tsv')
"""
예제 #9
0
    """
    alpha = l1_reg+l2_reg
    l1_ratio = l1_reg/alpha

    model = SGDRegressor(
        penalty='elasticnet',
        fit_intercept=False,
        alpha=alpha,
        l1_ratio=l1_ratio,
    )

    total_columns = A.shape[1]
    ranges = generate_slices(total_columns)
    separated_tasks = []

    for from_j, to_j in ranges:
        separated_tasks.append([from_j, to_j, A, model])

    pool = multiprocessing.Pool()
    pool.map(work, separated_tasks)
    pool.close()
    pool.join()

    return shared_array

W = slim_train(A)

recommendations = slim_recommender(A, W)

compute_precision(recommendations, test_file)
예제 #10
0
def main(train_file, part_file, test_file):

    AG = tsv_to_matrix(train_file, 942, 1682)
    AP = tsv_to_matrix(part_file, 942, 1682)

    W1 = slim_train(AG)
    W2 = slim_train(AP)
    # total_precision = []
    k = 2
    matrix_5 = np.zeros((21, k))
    matrix_10 = np.zeros((21, k))
    matrix_15 = np.zeros((21, k))
    matrix_20 = np.zeros((21, k))

    for i in range(0, 105, 5):
        gu = i / 100
        W = gu * W1 + (1 - gu) * W2
        print("gu: " + str(gu))
        recommendations = slim_recommender(AP, W)
        top5, top10, top15, top20 = compute_precision(recommendations,
                                                      test_file)
        for j in range(2):
            matrix_5[int(i / 5)][j] = top5[j]
            matrix_10[int(i / 5)][j] = top10[j]
            matrix_15[int(i / 5)][j] = top15[j]
            matrix_20[int(i / 5)][j] = top20[j]

    hr_values = []
    hr_values1 = []
    index1, value1 = max(enumerate(matrix_5[:, 0]), key=operator.itemgetter(1))
    index2, value2 = max(enumerate(matrix_10[:, 0]),
                         key=operator.itemgetter(1))
    index3, value3 = max(enumerate(matrix_15[:, 0]),
                         key=operator.itemgetter(1))
    index4, value4 = max(enumerate(matrix_20[:, 0]),
                         key=operator.itemgetter(1))
    hr_values.append(index1 * 0.05)
    hr_values.append(value1)
    hr_values.append(index2 * 0.05)
    hr_values.append(value2)
    hr_values.append(index3 * 0.05)
    hr_values.append(value3)
    hr_values.append(index4 * 0.05)
    hr_values.append(value4)
    hr_values1.append(matrix_5[20][0])
    hr_values1.append(matrix_10[20][0])
    hr_values1.append(matrix_15[20][0])
    hr_values1.append(matrix_20[20][0])

    arhr_values = []
    arhr_values1 = []
    index1, value1 = max(enumerate(matrix_5[:, 1]), key=operator.itemgetter(1))
    index2, value2 = max(enumerate(matrix_10[:, 1]),
                         key=operator.itemgetter(1))
    index3, value3 = max(enumerate(matrix_15[:, 1]),
                         key=operator.itemgetter(1))
    index4, value4 = max(enumerate(matrix_20[:, 1]),
                         key=operator.itemgetter(1))

    arhr_values.append(index1 * 0.05)
    arhr_values.append(value1)
    arhr_values.append(index2 * 0.05)
    arhr_values.append(value2)
    arhr_values.append(index3 * 0.05)
    arhr_values.append(value3)
    arhr_values.append(index4 * 0.05)
    arhr_values.append(value4)

    arhr_values1.append(matrix_5[20][1])
    arhr_values1.append(matrix_10[20][1])
    arhr_values1.append(matrix_15[20][1])
    arhr_values1.append(matrix_20[20][1])

    print('k8 top5: %s' % (matrix_5))
    print('k8 top10: %s' % (matrix_10))
    print('k8 top15: %s' % (matrix_15))
    print('k8 top20: %s' % (matrix_20))

    print('Max HR: %s' % (hr_values))
    print('HR at gu = 1: %s' % (hr_values1))
    print('Max ARHR: %s' % (arhr_values))
    print('ARHR at gu = 1: %s' % (arhr_values1))