Пример #1
0
        predictions = rs.recommend(target_data['playlist_id'])
        map_ = (evaluator.evaluate(predictions, test_data))
        map_list.append(map_)
        df = df.append(
            pd.DataFrame([[k, map_, shrinkage]], columns=['knn', 'map',
                                                          'shr']))
        top_50 = df.sort_values(by=['map']).tail(50)
        knn_list.append(k)
        k += 10

    print(top_50)
    if plot_graph:
        plt.plot(knn_list, map_list, 'bs')
        plt.title(shrinkage)
        plt.show()
    save_dataframe('../output/content_w_tuning_df.csv', ',', df)

    shrinkage += 10
print(top_50)
print('End of parameter tuning')
'''
from cbfRS.cbfRS import CbfRS
from loader.loader import save_dataframe, train_data, target_data, full_data, test_data, tracks_data
from utils.auxUtils import Evaluator


evaluator = Evaluator()
i = 0
list_map = []

while i < 6:
Пример #2
0
while shrinkage < 600:
    map_list = []
    knn_list = []
    k = 100
    while k <= 800:
        rs = ColBfIIRS(10, k, shrinkage, tf_idf=True)
        rs.fit(train_data)
        print('knn: ', k, ' shrinkage: ', shrinkage)
        predictions = rs.recommend(target_data['playlist_id'])
        map_ = (evaluator.evaluate(predictions, test_data))
        map_list.append(map_)
        df = df.append(
            pd.DataFrame([[k, map_, shrinkage]], columns=['knn', 'map',
                                                          'shr']))
        top_50 = df.sort_values(by=['map']).tail(50)
        knn_list.append(k)
        k += 50

    print(top_50)
    shrinkage += 50
    if plot_graph:
        plt.plot(knn_list, map_list, 'bs')
        plt.title(shrinkage)
        plt.show()

    save_dataframe('../output/coll_item_item_tuning_df.csv', ',', df)

print(top_50)
print("End of parameter tuning")
Пример #3
0
# Get values of both in common structure of CF
W_sparse_delta = W_sparse_CBF.copy().multiply(W_sparse_common)
W_sparse_delta -= W_sparse_CF.copy().multiply(W_sparse_common)

W_sparse_delta_sorted = np.sort(W_sparse_delta.data.copy())
'''
pyplot.plot(W_sparse_CF_sorted, label='CF')
pyplot.plot(W_sparse_CBF_sorted, label='CBF')
'''
pyplot.plot(W_sparse_delta_sorted, label='delta')
pyplot.ylabel('Similarity cell ')
pyplot.xlabel('Similarity value')
pyplot.legend()
pyplot.show()

print(
    "W collaborative item item has {:.2E} values and {:.2f} % in common with CBF"
    .format(W_sparse_CF.nnz, W_sparse_common.nnz / W_sparse_CF.nnz * 100))
print("W content has {:.2E} values and {:.2f} % in common with CF".format(
    W_sparse_CBF.nnz, W_sparse_common.nnz / W_sparse_CBF.nnz * 100))

print("W_sparse_delta has {:.2E} values".format(W_sparse_delta.nnz))

W_sparse_delta = W_sparse_delta.tocoo()
CFW_weithing = CFW_D_Similarity_Linalg(URM_train, ICM_all, W_sparse_CF,
                                       train_data)
CFW_weithing.fit()
prediction = CFW_weithing.recommend(target_data['playlist_id'])
evaluator.evaluate(prediction, test_data)
save_dataframe('output/hybrid_submission.csv', ',', prediction)
Пример #4
0
while shrinkage < 300:
    map_list = []
    knn_list = []
    k = 50
    while k < 500:
        rs = ColBfUURS(10, k, shrinkage, tf_idf=True)
        rs.fit(train_data)
        print('knn: ', k, ' shrinkage: ', shrinkage)
        predictions = rs.recommend(target_data['playlist_id'])
        map_ = (evaluator.evaluate(predictions, test_data))
        map_list.append(map_)
        df = df.append(
            pd.DataFrame([[k, map_, shrinkage]], columns=['knn', 'map',
                                                          'shr']))
        top_50 = df.sort_values(by=['map']).tail(50)
        k += 50

    print(top_50)

    if plot_graph:
        plt.plot(knn_list, map_list, 'bs')
        plt.title(shrinkage)
        plt.show()

    shrinkage += 25
    save_dataframe('../output/coll_user_user_tuning.csv', ',', top_50)

print(top_50)
print("End of parameter tuning")
Пример #5
0
                pd.DataFrame([[alpha, beta, gamma, temp_map]],
                             columns=['alpha', 'beta', 'gamma', 'map']))
            top_10 = df.sort_values(by=['map']).tail(10)

            gamma += 1

            print(top_10)

        beta += 1
    alpha += 1

# print(df)
top_50 = df.sort_values(by=['map']).tail(50)
print("FINAL RESULTS")
print(top_50)
save_dataframe('output/hybrid_col_uu_col_ii_cbf.csv', ',', df)
'''
Old tuning:
# Hybrid (cbf - colf)
rs = HybridRS(tracks_data, 10, tf_idf=True)
evaluator = Evaluator()
rs.fit(train_data)
delta = 0.5
while delta <= 1:
    slim_p = rs.recommend_probability(target_data['playlist_id'], 3, 6, 2, delta)
    evaluator.evaluate(slim_p, test_data)
    slim = rs.recommend(target_data['playlist_id'], 3, 6, 2, delta)
    evaluator.evaluate(slim, test_data)
    delta += 0.1

# print(df)
Пример #6
0
            r.fit(buildURMMatrix(train_data))
            pred = r.recommend(target_data['playlist_id'])
            temp_map = e.evaluate(pred, test_data)

            print("Alpha: ", a)
            print("Reg: ", reg)
            print("Num factors: ", nf)
            print("MAP: ", temp_map)
'''
'''
for r in regs:
    rs = IALS_numpy(num_factors=250, reg=r)
    e = Evaluator()

    rs.fit(buildURMMatrix(train_data))
    pred = rs.recommend(target_data['playlist_id'])
    temp_map = e.evaluate(pred, test_data)
    print("Regularization: ", r)
    print("MAP: ", temp_map)
'''

rs = IALS_numpy(num_factors=2, reg=100)
e = Evaluator()

rs.fit(buildURMMatrix(train_data))
print("GOING")
print(rs.get_estimated_ratings())
pred = rs.recommend(target_data['playlist_id'])
e.evaluate(pred, test_data)
save_dataframe('output/als_250_100_reg_factors.csv', sep=',', dataframe=pred)
Пример #7
0
from graphBased.p3alpha import P3alphaRecommender
from loader.loader import save_dataframe, train_data, target_data, full_data, test_data, tracks_data
from utils.auxUtils import Evaluator

evaluator = Evaluator()
rs = P3alphaRecommender(train_data)
# best values 1.1, topK= 75
rs.fit()
predictions = rs.recommend(target_data['playlist_id'])
map_ = (evaluator.evaluate(predictions, test_data))

save_dataframe('output/p3_alpha_tuning.csv', ',', predictions)
Пример #8
0
# from lightfm import LightFM
from cbfRS.cbfRS import CbfRS
from collaborative_filtering_RS.col_user_userRS import ColBfUURS
from collaborative_filtering_RS.col_item_itemRS import ColBfIIRS
from hybrid_col_cbf_RS.hybridRS import HybridRS
from slimRS.Cython.SLIM_BPR_Cython import SLIM_BPR_Cython
# from hybrid_col_cbf_RS.hybrid_pureSVD import HybridRS
from svdRS.pureSVD import PureSVDRecommender
import matplotlib.pyplot as plt
from slimRS.slimElasticNet import SLIMElasticNetRecommender
from hybrid_col_cbf_RS.hybrid_als_knn_slimBPR_elasticNet import HybridRS

rs = HybridRS(tracks_data)
rs.fit(full_data)
pred = rs.recommend(target_data['playlist_id'])
save_dataframe('output/hybrid_als.csv', sep=',', dataframe=pred)
''' PHI TUNNING
map_list = []
phi_list = []
phis = [8, 10, 12, 14, 16, 18, 20, 22, 24]
evaluator = Evaluator()
rs = HybridRS(tracks_data)
rs.fit(train_data)
for phi in phis:

    predictions = rs.recommend(target_data['playlist_id'], phi=phi)
    map_ = evaluator.evaluate(predictions, test_data)
    print("PHI: ", phi)
    print("MAP: ", map_)
    map_list.append(map_)
    phi_list.append(phi)