LoslegenKostenlos loslegen

Normalize your data

Before you can find the factors of the ratings matrix using singular value decomposition, you will need to "de-mean", or center it, by subtracting each row's mean from each value in that row.

In this exercise, you will begin prepping the movie rating DataFrame you have been working with in order to be able to perform Singular value decomposition.

user_ratings_df contains a row per user and a column for each movie and has been loaded for you.

Diese Übung ist Teil des Kurses

Building Recommendation Engines in Python

Kurs anzeigen

Anleitung zur Übung

  • Find the average rating each user has given across all the movies they have seen and store these values as avg_ratings.
  • Subtract the row averages from their respective rows and store the result as user_ratings_centered.
  • Finally, fill in all missing values in user_ratings_centered with zeros.
  • Print the average of each column in user_ratings_centered to show they have been de-meaned.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Get the average rating for each user 
avg_ratings = user_ratings_df.____(axis=1)

# Center each user's ratings around 0
user_ratings_centered = user_ratings_df.____(____, axis=1)

# Fill in all missing values with 0s
user_ratings_centered.____(0, inplace=True)

# Print the mean of each column
print(user_ratings_centered.____(axis=1))
Code bearbeiten und ausführen