Ejemplo n.º 1
0
def pick_out_genres():
    '''Used for picking out genres.
    Shows the index and weight corresponding to the highest weighted movies
    of each eigenvector.
    '''
    movie_matrix = movies.get_matrix_from_data()

    (ls, sv, rs) = svdP(5, .01, movie_matrix)
    for vec in rs:
        tups = []
        it = np.nditer(vec, flags=['f_index'])
        while not it.finished:
            tups.append((it[0], it.index))
            it.iternext()
        print sorted(tups, reverse=True)[:10]  # Best movies in each genre
Ejemplo n.º 2
0
def pick_out_genres():
    """Used for picking out genres.
    Shows the index and weight corresponding to the highest weighted movies
    of each eigenvector.
    """
    movie_matrix = movies.get_matrix_from_data()

    (ls, sv, rs) = svdP(5, 0.01, movie_matrix)
    for vec in rs:
        tups = []
        it = np.nditer(vec, flags=["f_index"])
        while not it.finished:
            tups.append((it[0], it.index))
            it.iternext()
        print sorted(tups, reverse=True)[:10]  # Best movies in each genre
Ejemplo n.º 3
0
def analyze_movies():
    '''Analyzes the accuracy of SVD with increasing k'''
    movie_matrix = movies.get_matrix_from_data()

    # Test reconstruction accuracy
    ks = [5 + 5 * i for i in range(20)]
    norms = []
    for k in ks:
        print k
        (ls, sv, rs) = svdP(k, .01, movie_matrix)
        recon = reconstruct(ls, sv, rs)
        diff = abs(movie_matrix - recon)
        norms.append(np.linalg.norm(diff)**2)

    plt.plot(ks, norms)
    plt.xlabel("Number of singular values")
    plt.ylabel("Square of Frobenius Norm")
    plt.show()
Ejemplo n.º 4
0
def analyze_movies():
    """Analyzes the accuracy of SVD with increasing k"""
    movie_matrix = movies.get_matrix_from_data()

    # Test reconstruction accuracy
    ks = [5 + 5 * i for i in range(20)]
    norms = []
    for k in ks:
        print k
        (ls, sv, rs) = svdP(k, 0.01, movie_matrix)
        recon = reconstruct(ls, sv, rs)
        diff = abs(movie_matrix - recon)
        norms.append(np.linalg.norm(diff) ** 2)

    plt.plot(ks, norms)
    plt.xlabel("Number of singular values")
    plt.ylabel("Square of Frobenius Norm")
    plt.show()