Skip to content

Instantly share code, notes, and snippets.

@jfkirk
Last active January 19, 2019 21:13
Show Gist options
  • Save jfkirk/60d6fd2d704c0762eb2491ffdd3821d4 to your computer and use it in GitHub Desktop.
Save jfkirk/60d6fd2d704c0762eb2491ffdd3821d4 to your computer and use it in GitHub Desktop.
# Create sets of train/test interactions that are only ratings >= 4.0
sparse_train_ratings_4plus = sparse_train_ratings.multiply(sparse_train_ratings >= 4.0)
sparse_test_ratings_4plus = sparse_test_ratings.multiply(sparse_test_ratings >= 4.0)
# This method consumes item ranks for each user and prints out recall@10 train/test metrics
def check_results(ranks):
train_recall_at_10 = tensorrec.eval.recall_at_k(
test_interactions=sparse_train_ratings_4plus,
predicted_ranks=ranks,
k=10
).mean()
test_recall_at_10 = tensorrec.eval.recall_at_k(
test_interactions=sparse_test_ratings_4plus,
predicted_ranks=ranks,
k=10
).mean()
print("Recall at 10: Train: {:.4f} Test: {:.4f}".format(train_recall_at_10,
test_recall_at_10))
# Check the results of the MF CF model
print("Matrix factorization collaborative filter:")
predicted_ranks = cf_model.predict_rank(user_features=user_indicator_features,
item_features=item_indicator_features)
check_results(predicted_ranks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment