ComeçarComece de graça

Comparing item-based and user-based models

You have now looked at two different KNN approaches. The first was item-item KNN where you use the average of the \(k\) most similar movies that a user has rated to suggest a rating for a movie they haven't watched. The other approach was user-user KNN where you use the average of the ratings that the \(k\) most similar users gave the movie to suggest what rating the target user would give the movie.

Now, you will compare the two and calculate what rating user_002 would give to Forrest Gump.

The code for the user_rating_predictor model (that predicts based on what similar users gave the movie), and the movie_rating_predictor (that predicts based off of what ratings this user gave to similar movies) has been started for you.

KNeighborsRegressor has been imported for you.

Este exercício faz parte do curso

Building Recommendation Engines in Python

Ver curso

Instruções do exercício

  • Create a user-user K-nearest neighbors model called user_knn.
  • Fit the user_knn model then predict on target_user_x.
  • Similarly, fit an item-item K-nearest neighbors model called movie_knn, then predict ontarget_movie_x.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Instantiate the user KNN model
user_knn = ____()

# Fit the model and predict the target user
user_knn.____(other_users_x, other_users_y)
user_user_pred = user_knn.____(target_user_x)
print("The user-user model predicts {}".format(user_user_pred))

# Instantiate the user KNN model
movie_knn = KNeighborsRegressor()

# Fit the model on the movie data and predict
movie_knn.____(other_movies_x, other_movies_y)
item_item_pred = movie_knn.____(target_movie_x)
print("The item-item model predicts {}".format(item_item_pred))
Editar e executar o código