Esempio n. 1
0
                    train_params = {
                        "alpha": alpha,
                        "regularization": regularization,
                        "latent_features": latent_features,
                        "learning_rate": learning_rate,
                        "percent_zeros": percent_zero
                    }
                    results = 0
                    for run in range(params["number_of_runs"]):
                        T = {}
                        new_playlist_tracks = {}
                        for input_playlist_index in range(
                                params["number_of_playlists_to_test"]):
                            input_pid = indexed_pids[input_playlist_index]
                            T[input_pid], new_playlist_tracks[
                                input_pid] = matrix.split_playlist(
                                    input_pid, playlist_dict)
                            matrix.update_input_playlist_tracks(
                                input_playlist_index,
                                new_playlist_tracks[input_pid],
                                track_playlist_matrix, unique_track_dict)

                        factorized_matrix = nn_mf.get_factorized_matrix(
                            mongo_collection, track_playlist_matrix,
                            train_params)

                        for input_playlist_index in range(
                                params["number_of_playlists_to_test"]):
                            input_pid = indexed_pids[input_playlist_index]

                            ranked_tracks = nn_mf.get_ranked_tracks(
                                factorized_matrix, input_playlist_index,
input_playlist_index = 0
for index, pid in enumerate(indexed_pids):
    if pid == input_pid:
        input_playlist_index = index
        break

avg_ndcg = {}
avg_r = {}
for N in range(1, max_N + 1):
    avg_ndcg[N] = 0
    avg_r[N] = 0

num_runs = 10
for run in range(num_runs):
    T, new_playlist_tracks = matrix.split_playlist(input_pid, playlist_dict)
    matrix.update_input_playlist_tracks(input_playlist_index, new_playlist_tracks, track_playlist_matrix, unique_track_dict)

    ranked_tracks = []
    if rec_system == 'item':
        ranked_tracks = item_based.get_ranked_tracks(new_playlist_tracks, indexed_tids, track_playlist_matrix, mongo_collection)
    elif rec_system == 'user':
        ranked_tracks = user_based.get_ranked_tracks(input_pid, input_playlist_index, playlist_dict, unique_track_dict, track_playlist_matrix, mongo_collection)
    elif rec_system == 'mf':
        factorized_matrix = matrix_factorization.get_factorized_matrix(mongo_collection, track_playlist_matrix)
        ranked_tracks = matrix_factorization.get_ranked_tracks(factorized_matrix, input_playlist_index, indexed_tids)
    elif rec_system == 'feature_mf':
        feature_matrix = []
        for tid in unique_track_dict.keys():
            feature_matrix.append([
                unique_track_dict[tid]["danceability"],