Exemplo n.º 1
0
test_user_name = "user_000691"
# number of songs to be recommend
recommended_num = 100
# number of similar neighbours
num_neighbours = 3
# number of maximum neighbours to be allowed
max_neighbours = 10

# get rating matrix part

# get MSD track dictionary
(unique_tracks_info_dict,
    unique_tracks_info_dict_reverse) = msd.read_tracks_database(
        filename_subset)
# get user play history within MSD
user_log_MSD, user_track_timestamp_MSD = msd.read_intersect_user_log(
    user_log_intersection, unique_tracks_info_dict)
# get user rating matrix
user_rate_dict = msd.get_track_rating_from_history(user_track_timestamp_MSD)
# get each user's mean rating score line
user_mean_votes_dict = ck.get_mean_vote_dict(user_rate_dict)

# get nearest neighbours
if os.path.isfile(similar_weight_user_filename):
    user_knn_dict = ck.read_neighbours(
        similar_weight_user_filename, num_neighbours)
else:
    full_user_his = tu.read_full_user_log(user_log_filename)
    user_knn_dict = ck.get_write_knn(
        full_user_his, num_neighbours,
        similar_weight_user_filename, max_neighbours)
    ck.write_neighbours(user_knn_dict, similar_weight_user_filename)
Exemplo n.º 2
0
# randomly pick a test user from 1k user
test_user_name = "user_000691"
# number of songs to be recommend
recommended_num = 100
# number of similar neighbours
num_neighbours = 3
# number of maximum neighbours to be allowed
max_neighbours = 10

# get rating matrix part

# get MSD track dictionary
(unique_tracks_info_dict,
 unique_tracks_info_dict_reverse) = msd.read_tracks_database(filename_subset)
# get user play history within MSD
user_log_MSD, user_track_timestamp_MSD = msd.read_intersect_user_log(
    user_log_intersection, unique_tracks_info_dict)
# get user rating matrix
user_rate_dict = msd.get_track_rating_from_history(user_track_timestamp_MSD)
# get each user's mean rating score line
user_mean_votes_dict = ck.get_mean_vote_dict(user_rate_dict)

# get nearest neighbours
if os.path.isfile(similar_weight_user_filename):
    user_knn_dict = ck.read_neighbours(similar_weight_user_filename,
                                       num_neighbours)
else:
    full_user_his = tu.read_full_user_log(user_log_filename)
    user_knn_dict = ck.get_write_knn(full_user_his, num_neighbours,
                                     similar_weight_user_filename,
                                     max_neighbours)
    ck.write_neighbours(user_knn_dict, similar_weight_user_filename)