コード例 #1
0
 def __init__(self):
     """ init method which initialises the object """
     reader = DBReader()
     self.all_movies = reader.read_movies() 
     self.all_ratings = reader.read_ratings()
     self.all_genre = reader.read_genre()
     self.all_users = reader.read_users()
コード例 #2
0
ファイル: warmup.py プロジェクト: nvnvenki/MovieRecommender
    """ Method to get the most active user """
    if all_ratings and all_users and len(all_users) and len(all_ratings):
        
        user_id_dict = {}
        for rating in all_ratings:
            if user_id_dict.has_key(rating['user_id']):
                user_id_dict[rating['user_id']] = user_id_dict[rating['user_id']] + 1
            else:
                user_id_dict[rating['user_id']] = 0
        return max(user_id_dict.iteritems(), key=operator.itemgetter(1))[0]
    
    
if __name__ == '__main__':
    """ Test of methods """
    reader = DBReader()
    all_genres = reader.read_genre()
    all_movies = reader.read_movies()
    all_ratings = reader.read_ratings()
    all_users = reader.read_users()
    
    '''
    movies = get_top_movie_by_genre(all_genres,all_movies,all_ratings)
    for each_genre in movies:
        print "=" * 40
        print "Top 5 movies of ", each_genre 
        print "=" * 40
        for each_movie in movies[each_genre]:
            print each_movie.get_title() , each_movie.ratings
        print "=" * 40
        
    movies = get_top_movie_by_year(all_genres,all_movies,all_ratings)
コード例 #3
0
def main():
    """ Test cases """
    # --------------------------------------------------------------------
    #                      For warm up problems
    #---------------------------------------------------------------------
    reader = DBReader()
    all_genres = reader.read_genre()
    all_movies = reader.read_movies()
    all_ratings = reader.read_ratings()
    all_users = reader.read_users()
    
    
    movies = get_top_movie_by_genre(all_genres,all_movies,all_ratings)
    for each_genre in movies:
        print "=" * 40
        print "Top 5 movies of ", each_genre 
        print "=" * 40
        for each_movie in movies[each_genre]:
            print each_movie.get_title() , each_movie.ratings
        print "=" * 40
        
    movies = get_top_movie_by_year(all_genres,all_movies,all_ratings)
    for each_year in movies:
        print "=" * 40
        print "Top movies of ", each_year 
        print "=" * 40
        for each_movie in movies[each_year]:
            print each_movie.get_title() , each_movie.ratings
        print "=" * 40
        
    movies = get_top_movie_by_year_and_genre(all_genres,all_movies,all_ratings)
    
    for each_year in movies:
        print "=" * 40
        print "Year ", each_year 
        print "=" * 40
        for genres in movies[each_year]:
            for each_genre in genres:
                if len(genres[each_genre]) > 1:
                    for m in genres[each_genre]:
                        print m.get_title()
    
    # highest watched movies is based on no of users who rated that movie
    movie = most_watched_movie(all_movies, all_ratings) 
    print "most watched movie", movie.title
    print "=" * 40
    
    genre = most_watched_genre(all_movies, all_ratings, all_genres)  
    print "Most watched genre : ", genre
    
    genre = highest_rated_genre(all_movies, all_ratings, all_genres) 
    print "Highest rated genre: ", genre
    
    user = most_active_user(all_users, all_ratings)
    print "Most active user is user with user id : ", user
    
    print "-" * 40
    # --------------------------------------------------------------------
    #                      For Assignment
    #---------------------------------------------------------------------
    
    recommender = Recommender()
    movies_recommended = recommender.recommend_for(16660)
    if movies_recommended is not None:
        print "-" * 35
        print "Recommended top 5 movies for you!"
        print "-" * 35
        for movie in movies_recommended:
            print movie.get_title()
        print "-" * 35
    movies_recommended = recommender.recommend_for(166)
    if movies_recommended is not None:
        print "-" * 35
        print "Recommended top 5 movies for you!"
        print "-" * 35
        for movie in movies_recommended:
            print movie.get_title()
        print "-" * 35