예제 #1
0
from basic_visualization import load_data, most_popular_movie
import numpy as np
import prob2utils
from collections import defaultdict, Counter
import matplotlib.pyplot as plt
import matplotlib
from textwrap import wrap

if __name__ == '__main__':

    # Get 10 best and most popular movies
    movie_genre, user_data, movie_dict = load_data(
        '../project3data/movies.txt', '../project3data/data.txt')

    genre_dict = [
        'Unknown', 'Action', 'Adventure', 'Animation', 'Childrens', 'Comedy',
        'Crime', 'Documentary', 'Drama', 'Fantasy', 'Film-Noir', 'Horror',
        'Musical', 'Mystery', 'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western'
    ]

    movie_ratings_dict = defaultdict(list)
    for key, rating in user_data[:, 1:]:
        movie_ratings_dict[key].append(rating)

    most_popular_movies, best_movies = most_popular_movie(movie_ratings_dict)

    V_proj = np.loadtxt('V_Proj.csv', delimiter=',')
    N = V_proj.shape[1]

    fig = plt.figure()
    ax = fig.add_subplot(111)
예제 #2
0
import basic_visualization
import matplotlib.pyplot as plt
import numpy as np
import random
from textwrap import wrap

#Load in movie data and projection of V
movie_genre, user_data, movie_dict = basic_visualization.load_data(
    '../project3data/movies.txt', '../project3data/data.txt')
V_proj = np.loadtxt('V_Proj.csv', delimiter=',')
N = V_proj.shape[1]

#Initialize variables
M = 10
rand_movies = np.empty([M, 2])
movie_names = []
movie_index = np.empty(M)

#Pick 10 random movies, and find their location on the V Projection
for i in range(M):
    index = random.randint(0, N - 1)
    rand_movies[i, :] = V_proj[:, index]
    movie_index[i] = index
    #movie_names[i] = movie_dict.get(index)
    movie_names.append(movie_dict.get(index))
print(movie_names)

plt.scatter(rand_movies[:, 0], rand_movies[:, 1], s=20)
for label, x, y in zip(movie_names, rand_movies[:, 0], rand_movies[:, 1]):
    plt.annotate(
        "\n".join(wrap(label, 18)),