From 2fd8ca7cf82a273abf5139ba7debb538bb8ee6f6 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Sat, 27 Aug 2022 10:14:54 +0200 Subject: [PATCH] Improve code style --- movies.py | 9 +++++---- movies_test.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/movies.py b/movies.py index 3212de3..858d463 100644 --- a/movies.py +++ b/movies.py @@ -1,7 +1,11 @@ +""" +Movie recommender system as a showcase project +""" + import collections import pandas as pd -import tensorflow as tf +# import tensorflow as tf def load_movielense(): """Load an return movies and ratings as dataframes""" @@ -24,6 +28,3 @@ def collect_user_context(ratings, min_rating=2.1): user_movies[user_id].append(movie_id) return user_movies - - - diff --git a/movies_test.py b/movies_test.py index a37ae83..07d0280 100644 --- a/movies_test.py +++ b/movies_test.py @@ -1,6 +1,10 @@ -import pandas as pd +""" +Test cases for the movie recommender system +""" + import unittest +import pandas as pd import movies class LoadTests(unittest.TestCase): @@ -9,20 +13,19 @@ class LoadTests(unittest.TestCase): @staticmethod def toy_ratings(): """Return a toy dataframe with ratings""" - return pd.DataFrame(data={ + return pd.DataFrame({ "userId": [1, 1, 2, 2, 1], "movieId": [1, 2, 1, 3, 4], "rating": [3, 1, 4, 3, 5], "timestamp": [1, 2, 7, 5, 4], }, columns=["userId", "movieId", "rating", "timestamp"]) - + def test_collect_user_context(self): """Check that ratings are correctly aggregated""" rating = self.toy_ratings() user_movies = movies.collect_user_context(rating) - - self.assertEqual(user_movies[1], [1, 4]) - self.assertEqual(user_movies[2], [3, 1]) - self.assertEqual(set(user_movies.keys()), {1, 2}) + self.assertEqual(user_movies[1], [1, 4]) + self.assertEqual(user_movies[2], [3, 1]) + self.assertEqual(set(user_movies.keys()), {1, 2}) -- GitLab