<s> import numpy as np <EOL> from numpy . testing import assert_array_equal <EOL> from nose . tools import assert_raises , assert_equals , assert_almost_equals <EOL> from ... . models . classes import MatrixPreferenceDataModel , MatrixBooleanPrefDataModel <EOL> from . . item_strategies import ItemsNeighborhoodStrategy , AllPossibleItemsStrategy <EOL> from . . neighborhood_strategies import AllNeighborsStrategy , NearestNeighborsStrategy <EOL> from ... . similarities . basic_similarities import ItemSimilarity , UserSimilarity <EOL> from . . classes import ItemBasedRecommender , UserBasedRecommender <EOL> from ... . models . utils import ItemNotFoundError , UserNotFoundError <EOL> from ... . metrics . pairwise import euclidean_distances , jaccard_coefficient , pearson_correlation <EOL> movies = { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { } } <EOL> matrix_model = MatrixPreferenceDataModel ( movies ) <EOL> boolean_matrix_model = MatrixBooleanPrefDataModel ( movies ) <EOL> def test_create_ItemBasedRecommender ( ) : <EOL> items_strategy = AllPossibleItemsStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_equals ( recsys . similarity , similarity ) <EOL> assert_equals ( recsys . items_selection_strategy , items_strategy ) <EOL> assert_equals ( recsys . model , matrix_model ) <EOL> assert_equals ( recsys . capper , True ) <EOL> def test_create_UserBasedRecommender ( ) : <EOL> nhood_strategy = AllNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_equals ( recsys . similarity , similarity ) <EOL> assert_equals ( recsys . neighborhood_strategy , nhood_strategy ) <EOL> assert_equals ( recsys . model , matrix_model ) <EOL> assert_equals ( recsys . capper , True ) <EOL> def test_all_other_items_ItemBasedRecommender ( ) : <EOL> items_strategy = AllPossibleItemsStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> similarity = ItemSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> def test_all_other_items_UserBasedRecommender ( ) : <EOL> nhood_strategy = AllNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = pearson_correlation , nhood_size = <NUM_LIT:2> , minimal_similarity = <NUM_LIT:0.1> ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = pearson_correlation , nhood_size = <NUM_LIT:2> , minimal_similarity = <NUM_LIT:0.1> ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = pearson_correlation , nhood_size = <NUM_LIT:2> , minimal_similarity = <NUM_LIT:0.1> ) ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . all_other_items ( '<STR_LIT>' ) ) <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , pearson_correlation ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = pearson_correlation , nhood_size = <NUM_LIT:2> , minimal_similarity = <NUM_LIT:0.1> ) ) <EOL> assert_array_equal ( np . array ( [ ] , dtype = '<STR_LIT>' ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = pearson_correlation , nhood_size = <NUM_LIT:3> ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , <EOL> recsys . all_other_items ( user_id = '<STR_LIT>' , distance = euclidean_distances , nhood_size = <NUM_LIT:2> ) ) <EOL> def test_estimate_preference_ItemBasedRecommender ( ) : <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy , False ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . nan , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy , False ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . NaN , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_estimate_preference_UserBasedRecommender ( ) : <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT> , <EOL> recsys . estimate_preference ( user_id = '<STR_LIT>' , item_id = '<STR_LIT>' , <EOL> distance = pearson_correlation , nhood_size = <NUM_LIT:4> , minimal_similarity = - <NUM_LIT:1.0> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_almost_equals ( <NUM_LIT> , <EOL> recsys . estimate_preference ( user_id = '<STR_LIT>' , item_id = '<STR_LIT>' , <EOL> nhood_size = <NUM_LIT:4> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy , False ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT> , <EOL> recsys . estimate_preference ( user_id = '<STR_LIT>' , item_id = '<STR_LIT>' , <EOL> distance = pearson_correlation , nhood_size = <NUM_LIT:4> , minimal_similarity = - <NUM_LIT:1.0> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy , False ) <EOL> assert_almost_equals ( <NUM_LIT> , <EOL> recsys . estimate_preference ( user_id = '<STR_LIT>' , item_id = '<STR_LIT>' , <EOL> nhood_size = <NUM_LIT:4> ) ) <EOL> assert_array_equal ( np . nan , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , <EOL> recsys . estimate_preference ( user_id = '<STR_LIT>' , item_id = '<STR_LIT>' , <EOL> distance = jaccard_coefficient , nhood_size = <NUM_LIT:3> ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy , False ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . NaN , recsys . estimate_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_most_similar_items_ItemBasedRecommender ( ) : <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:4> ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' ) ) <EOL> assert_raises ( ItemNotFoundError , recsys . most_similar_items , '<STR_LIT>' ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:4> ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' ) ) <EOL> assert_raises ( ItemNotFoundError , recsys . most_similar_items , '<STR_LIT>' ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_items ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def test_most_similar_users_UserBasedRecommender ( ) : <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:4> ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_users ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:4> ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_users ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . most_similar_users ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> def test_recommend_ItemBasedRecommender ( ) : <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys . recommend ( user_id = '<STR_LIT>' , similarity = similarity ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy , True , True ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> similarity = ItemSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys . recommend ( user_id = '<STR_LIT>' , similarity = similarity ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy , True , True ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> def test_recommend_UserBasedRecommender ( ) : <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys . recommend ( user_id = '<STR_LIT>' , similarity = similarity ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy , True , True ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> assert_almost_equals ( <NUM_LIT> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' ] ) , recsys . recommend ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys . recommend ( user_id = '<STR_LIT>' , similarity = similarity ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommend ( '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy , True , True ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( '<STR_LIT>' , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> assert_almost_equals ( <NUM_LIT:1.0> , recsys . recommend ( '<STR_LIT>' ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> def test_recommend_because_ItemBasedRecommender ( ) : <EOL> items_strategy = ItemsNeighborhoodStrategy ( ) <EOL> similarity = ItemSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = ItemBasedRecommender ( matrix_model , similarity , items_strategy , True , True ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> similarity = ItemSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = ItemBasedRecommender ( boolean_matrix_model , similarity , items_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> def test_recommend_because_UserBasedRecommender ( ) : <EOL> nhood_strategy = NearestNeighborsStrategy ( ) <EOL> similarity = UserSimilarity ( matrix_model , euclidean_distances ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = UserBasedRecommender ( matrix_model , similarity , nhood_strategy , True , True ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> similarity = UserSimilarity ( boolean_matrix_model , jaccard_coefficient ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> recsys = UserBasedRecommender ( boolean_matrix_model , similarity , nhood_strategy ) <EOL> assert_array_equal ( np . array ( [ ] ) , recsys . recommended_because ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) ) </s>
