def __top_n_movies_for_user_id(self, knn_dict):

        # compute the predicted ratings of user_id for each movie, and select top
        # n movies which have got higher prediction ratings.
        mat = self.__data.um_mat
        n_cols = self.__data.n_cols
        mat_t = np.matrix.transpose(mat)
        m = 0
        m_dict = {}
        for movie in mat_t:
            pr = 0.0
            for u, v in knn_dict:
                pr += movie[u] * v
            m_dict[m] = pr
            m += 1

        top_n_list = compute.get_top_n_movies(m_dict, mat, self.__data.user_id, self.__data.top_n)
        return top_n_list
  def __top_n_movies_for_user_id(self, knn_list):

    # compute the frequency count of each movie for top k nearest neighbors
    mat = self.__data.um_mat
    n_cols = self.__data.n_cols
    movie_arr = np.zeros(n_cols)
    for k in knn_list:
      movie_arr = np.add(movie_arr, mat[k])

    # create a dictionary from movie frequency count array
    m_dict = {}
    for i in range(0, n_cols):
      m_dict[i] = movie_arr[i]

    # select top n movies for users whose frequency counts is higher
    top_n_list = compute.get_top_n_movies(m_dict, mat, self.__data.user_id, \
                                          self.__data.top_n)
    return top_n_list
Beispiel #3
0
    def __top_n_movies_for_user_id(self, knn_list):

        # compute the frequency count of each movie for top k nearest neighbors
        mat = self.__data.um_mat
        n_cols = self.__data.n_cols
        movie_arr = np.zeros(n_cols)
        for k in knn_list:
            movie_arr = np.add(movie_arr, mat[k])

        # create a dictionary from movie frequency count array
        m_dict = {}
        for i in range(0, n_cols):
            m_dict[i] = movie_arr[i]

        # select top n movies for users whose frequency counts is higher
        top_n_list = compute.get_top_n_movies(m_dict, mat, self.__data.user_id, \
                                              self.__data.top_n)
        return top_n_list