Exemple #1
0
    '127': 1,
    '56': 5,
    '7': 5,
    '98': 3,
    '237': 5,
    '117': 4,
    '172': 4,
    '222': 5,
    '204': 3
}

#comes from Movie_Data_Frames module
rated_movies = ('50', '258', '100', '181', '294', '286', '288', '1', '300',
                '121', '174', '127', '56', '7', '98', '237', '117', '172',
                '222', '204')
df = build_dataframe(user_dict)


def build_evaluation_file(user_dict, k):
    """Takes dict input of user ratings and returns csv of to calculate error"""
    try:
        new_df = pd.DataFrame(list(user_dict.items()),
                              columns=['Movie ID', 'Ratings'])
        user_tr = new_df.set_index(
            ['Movie ID'])  #Application user's movie ratings in data frame

        #Create transposed versions of these dataframes in order to use the correlation method available in Pandas

        #df is the queried dataframe built using the build_dataframe function in line 35
        mean_df = df.fillna(
            df.mean()
    for film in range(len(movie_list)):
        if (film < (10 * multiple) and cont.lower()) == 'y':
            print(final_picks[film])
        elif len(final_picks) > 10:
            cont = input("Enter 'y' if you would like to see more films:\n ")
            if cont.lower()  == 'y':
                multiple +=1
            else:
                return(print("Thank you for using this service."))
                break

while True:
    user_dict = build_profile() #Function prompts uses to rate 20 movies.  The films presented have the largest number of reviews in the database
    k = eval(input("How many neighbors should be used for the recommendations? (k)")) #This is used for User CF and Item CF
    print("This should take a few seconds...finding great movies for you!")
    movie_df = build_dataframe(user_dict) #The dataframe is based on a query in the database getting ratings for all users who rated the same movies as the application's user
    cf_neighbors = build_similarity(user_dict, movie_df, k)#returns the nearest neighbors for the app user and their correlations 
    cf_movies = find_movies(user_dict,cf_neighbors) #returns movies with predicted ratings for the user
    
    final_picks = select_genres(cf_movies)#gives the app's user the choice to request films of a certain genre
    print(display_films(final_picks)) 
    
    e = input("I hoped those movies look good.  I'm going to try another way to find movies for you, press enter to start the process:\n")
    print("This should take a few seconds...finding great movies for you!")
    item_movies = item_item(user_dict, k) #Returns movies that are similar to items rated by the app user along with predicted rating
    
    final_picks = select_genres(item_movies)#gives the app's user the choice to request films of a certain genre
    print(display_films(final_picks))       
    
    
    e = input("I hoped those movies look good. \n Press 0 if you would like to exit or any key to start the process over:\n\n")
    "288",
    "1",
    "300",
    "121",
    "174",
    "127",
    "56",
    "7",
    "98",
    "237",
    "117",
    "172",
    "222",
    "204",
)
df = build_dataframe(user_dict)


def build_evaluation_file(user_dict, k):
    """Takes dict input of user ratings and returns csv of to calculate error"""
    try:
        new_df = pd.DataFrame(list(user_dict.items()), columns=["Movie ID", "Ratings"])
        user_tr = new_df.set_index(["Movie ID"])  # Application user's movie ratings in data frame

        # Create transposed versions of these dataframes in order to use the correlation method available in Pandas

        # df is the queried dataframe built using the build_dataframe function in line 35
        mean_df = df.fillna(df.mean())  # fill missing ratings with the mean rating across other users for each film.
        df_tr = mean_df.transpose()

        # Create objects to be used to calculate correlations