diff --git a/scikits/crab/models/classes.py b/scikits/crab/models/classes.py index 7799a7c..010dbf7 100644 --- a/scikits/crab/models/classes.py +++ b/scikits/crab/models/classes.py @@ -366,12 +366,12 @@ def __unicode__(self): lines = matrix.split('\n') headers = [repr(self)[1:-1]] if self._item_ids.size: - col_headers = [('%-8s' % item[:8]) for item in self._item_ids[:5]] + col_headers = [('%-8s' % unicode(item)[:8]) for item in self._item_ids[:5]] headers.append(' ' + (' '.join(col_headers))) if self._user_ids.size: for (i, line) in enumerate(lines): - lines[i] = ('%-8s' % self._user_ids[i][:8]) + line + lines[i] = ('%-8s' % unicode(self._user_ids[i])[:8]) + line for (i, line) in enumerate(headers): if i > 0: headers[i] = ' ' * 8 + line @@ -640,7 +640,7 @@ def preference_value(self, user_id, item_id): if not item_id_loc[0].size: raise ItemNotFoundError('item_id in the model not found') - return 1.0 if self.index[user_id_loc, item_id_loc].flatten()[0] else 0.0 + return 1.0 if self.index[user_id_loc, item_id_loc].flatten()[0] else np.NaN def set_preference(self, user_id, item_id, value=None): ''' @@ -737,12 +737,12 @@ def __unicode__(self): lines = matrix.split('\n') headers = [repr(self)[1:-1]] if self._item_ids.size: - col_headers = [('%-8s' % item[:8]) for item in self._item_ids[:5]] + col_headers = [('%-8s' % unicode(item)[:8]) for item in self._item_ids[:5]] headers.append(' ' + (' '.join(col_headers))) if self._user_ids.size: for (i, line) in enumerate(lines): - lines[i] = ('%-8s' % self._user_ids[i][:8]) + line + lines[i] = ('%-8s' % unicode(self._user_ids[i])[:8]) + line for (i, line) in enumerate(headers): if i > 0: headers[i] = ' ' * 8 + line diff --git a/scikits/crab/models/tests/test_models.py b/scikits/crab/models/tests/test_models.py index 107523b..590e624 100644 --- a/scikits/crab/models/tests/test_models.py +++ b/scikits/crab/models/tests/test_models.py @@ -5,6 +5,8 @@ from ..classes import MatrixPreferenceDataModel, \ MatrixBooleanPrefDataModel from ..utils import UserNotFoundError, ItemNotFoundError +from ...datasets import load_sample_songs + #Simple Movies DataSet movies = {'Marcel Caraciolo': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5, @@ -83,6 +85,24 @@ def test_basic_methods_MatrixPreferenceDataModel(): assert("MatrixPreferenceDataModel (8 by 6)" in model.__str__()) + #SampleSongs DataSet + songs = load_sample_songs() + model = MatrixPreferenceDataModel(songs.data) + assert_equals(model.dataset, songs.data) + assert_array_equal(np.array([1, 2, 3, 4, 5, 6, 7, 8]), + model.user_ids()) + assert_array_equal(np.array([1, 2, 3, 4, 5, 6, 7, 8]), model.item_ids()) + assert_equals(True, model.has_preference_values()) + assert_equals(8, model.users_count()) + assert_equals(8, model.items_count()) + assert_equals(5.0, model.maximum_preference_value()) + assert_equals(1.0, model.minimum_preference_value()) + assert_equals([(1, 2.5), (2, 3.5), (3, 5.0), (4, 2.0), (5, 4.5), (6, 1.5), (7, 2.0)], model[1]) + elements = [pref for pref in model] + assert_array_equal([(1, 2.5), (2, 3.5), (3, 5.0), (4, 2.0), (5, 4.5), (6, 1.5), (7, 2.0)], + elements[0][1]) + assert("MatrixPreferenceDataModel (8 by 8)" in model.__str__()) + def test_preferences_from_user_exists_MatrixPreferenceDataModel(): model = MatrixPreferenceDataModel(movies) @@ -191,6 +211,11 @@ def test_remove_preference_value_MatrixPreferenceDataModel(): 'Maria Gabriela': [] } +songs_boolean = {1: [1, 2, 3, 4, 5, 6, 7], 2: [1, 2, 3, 5, 6], + 3: [1, 2, 3, 4, 5, 6], 4: [1, 3, 4, 5, 6, 7, 8], + 5: [1, 2, 3, 4, 6, 7, 8], 6: [2, 3, 4, 6, 7, 8], + 7: [2, 3, 4, 5, 6, 8], 8: [8, 1, 4, 5, 7]} + def test_basic_methods_MatrixBooleanPrefDataModel(): #Empty Dataset @@ -222,6 +247,23 @@ def test_basic_methods_MatrixBooleanPrefDataModel(): 'Superman Returns', 'The Night Listener'], elements[0][1]) assert("MatrixBooleanPrefDataModel (8 by 6)" in model.__str__()) + songs = load_sample_songs() + model = MatrixBooleanPrefDataModel(songs.data) + assert_equals(model.dataset, songs_boolean) + assert_array_equal(np.array([1, 2, 3, 4, 5, 6, 7, 8]), + model.user_ids()) + assert_array_equal(np.array([1, 2, 3, 4, 5, 6, 7, 8]), model.item_ids()) + assert_equals(False, model.has_preference_values()) + assert_equals(8, model.users_count()) + assert_equals(8, model.items_count()) + assert_equals(1.0, model.maximum_preference_value()) + assert_equals(0.0, model.minimum_preference_value()) + assert_array_equal([1, 2, 3, 4, 5, 6, 7], model[1]) + elements = [pref for pref in model] + assert_array_equal([1, 2, 3, 4, 5, 6, 7], + elements[0][1]) + assert("MatrixBooleanPrefDataModel (8 by 8)" in model.__str__()) + def test_preferences_from_user_exists_MatrixBooleanPrefDataModel(): model = MatrixBooleanPrefDataModel(movies_boolean) @@ -287,7 +329,7 @@ def test_preference_value__invalid_MatrixBooleanPrefDataModel(): model = MatrixBooleanPrefDataModel(movies_boolean) assert_raises(UserNotFoundError, model.preference_value, 'Flavia', 'Superman Returns') assert_raises(ItemNotFoundError, model.preference_value, 'Marcel Caraciolo', 'Back to the future') - assert_array_equal(0.0, model.preference_value('Maria Gabriela', 'The Night Listener')) + assert_array_equal(np.NaN, model.preference_value('Maria Gabriela', 'The Night Listener')) def test_set_preference_value_MatrixBooleanPrefDataModel(): @@ -307,5 +349,5 @@ def test_set_preference_value_MatrixBooleanPrefDataModel(): def test_remove_preference_value_MatrixBooleanPrefDataModel(): model = MatrixBooleanPrefDataModel(movies_boolean) model.remove_preference('Maria Gabriela', 'Superman Returns') - assert_array_equal(0.0, model.preference_value('Maria Gabriela', 'Superman Returns')) + assert_array_equal(np.NaN, model.preference_value('Maria Gabriela', 'Superman Returns')) assert_raises(ItemNotFoundError, model.remove_preference, 'Marcel Caraciolo', 'Indiana Jones') diff --git a/scikits/crab/recommenders/knn/classes.py b/scikits/crab/recommenders/knn/classes.py index 7967bdf..bf96af3 100644 --- a/scikits/crab/recommenders/knn/classes.py +++ b/scikits/crab/recommenders/knn/classes.py @@ -95,12 +95,10 @@ class ItemBasedRecommender(ItemRecommender): >>> recsys = ItemBasedRecommender(model, similarity, items_strategy) >>> #Return the recommendations for the given user. >>> recsys.recommend('Leopoldo Pires') - array(['Just My Luck', 'You, Me and Dupree'],\ - dtype='|S18') + ['Just My Luck', 'You, Me and Dupree'] >>> #Return the 2 explanations for the given recommendation. >>> recsys.recommended_because('Leopoldo Pires', 'Just My Luck',2) - array(['The Night Listener', 'Superman Returns'],\ - dtype='|S18') + ['The Night Listener', 'Superman Returns'] Notes ----------- @@ -163,12 +161,16 @@ def estimate_preference(self, user_id, item_id, **params): item. If a preference cannot be estimated, returns None. ''' preference = self.model.preference_value(user_id, item_id) + if not np.isnan(preference): return preference #TODO: It needs optimization prefs = self.model.preferences_from_user(user_id) + if not self.model.has_preference_values(): + prefs = [(pref, 1.0) for pref in prefs] + similarities = \ np.array([self.similarity.get_similarity(item_id, to_item_id) \ for to_item_id, pref in prefs if to_item_id != item_id]).flatten() @@ -241,21 +243,21 @@ def _top_matches(self, source_id, target_ids, how_many=None, **params): preferences = estimate_preferences(source_id, target_ids) - preferences = preferences[~np.isnan(preferences)] + preference_values = preferences[~np.isnan(preferences)] target_ids = target_ids[~np.isnan(preferences)] - sorted_preferences = np.lexsort((preferences,))[::-1] + sorted_preferences = np.lexsort((preference_values,))[::-1] sorted_preferences = sorted_preferences[0:how_many] \ if how_many and sorted_preferences.size > how_many \ else sorted_preferences if self.with_preference: - top_n_recs = np.array([(target_ids[ind], \ - preferences[ind]) for ind in sorted_preferences]) + top_n_recs = [(target_ids[ind], \ + preferences[ind]) for ind in sorted_preferences] else: - top_n_recs = np.array([target_ids[ind] - for ind in sorted_preferences]) + top_n_recs = [target_ids[ind] + for ind in sorted_preferences] return top_n_recs @@ -280,7 +282,7 @@ def most_similar_items(self, item_id, how_many=None): self.similarity.num_best = old_how_many return np.array([item for item, pref in similarities \ - if item != item_id]) + if item != item_id and not np.isnan(pref)]) def recommended_because(self, user_id, item_id, how_many=None, **params): ''' @@ -332,11 +334,11 @@ def recommended_because(self, user_id, item_id, how_many=None, **params): else sorted_preferences if self.with_preference: - top_n_recs = np.array([(item_ids[ind], \ - prefs[ind]) for ind in sorted_preferences]) + top_n_recs = [(item_ids[ind], \ + prefs[ind]) for ind in sorted_preferences] else: - top_n_recs = np.array([item_ids[ind] - for ind in sorted_preferences]) + top_n_recs = [item_ids[ind] + for ind in sorted_preferences] return top_n_recs @@ -421,12 +423,10 @@ class UserBasedRecommender(UserRecommender): >>> recsys = UserBasedRecommender(model, similarity, nhood_strategy) >>> #Return the recommendations for the given user. >>> recsys.recommend('Leopoldo Pires') - array(['Just My Luck', 'You, Me and Dupree'],\ - dtype='|S18') + ['Just My Luck', 'You, Me and Dupree'] >>> #Return the 2 explanations for the given recommendation. >>> recsys.recommended_because('Leopoldo Pires', 'Just My Luck',2) - array(['Lorena Abreu', 'Marcel Caraciolo'],\ - dtype='|S16') + ['Lorena Abreu', 'Marcel Caraciolo'] Notes ----------- @@ -581,7 +581,7 @@ def most_similar_users(self, user_id, how_many=None): similarities = self.similarity[user_id] self.similarity.num_best = old_how_many return np.array([to_user_id for to_user_id, pref in similarities \ - if user_id != to_user_id]) + if user_id != to_user_id and not np.isnan(pref)]) def recommend(self, user_id, how_many=None, **params): ''' @@ -631,21 +631,21 @@ def _top_matches(self, source_id, target_ids, how_many=None, **params): preferences = estimate_preferences(source_id, target_ids) - preferences = preferences[~np.isnan(preferences)] + preference_values = preferences[~np.isnan(preferences)] target_ids = target_ids[~np.isnan(preferences)] - sorted_preferences = np.lexsort((preferences,))[::-1] + sorted_preferences = np.lexsort((preference_values,))[::-1] sorted_preferences = sorted_preferences[0:how_many] \ if how_many and sorted_preferences.size > how_many \ else sorted_preferences if self.with_preference: - top_n_recs = np.array([(target_ids[ind], \ - preferences[ind]) for ind in sorted_preferences]) + top_n_recs = [(target_ids[ind], \ + preferences[ind]) for ind in sorted_preferences] else: - top_n_recs = np.array([target_ids[ind] - for ind in sorted_preferences]) + top_n_recs = [target_ids[ind] + for ind in sorted_preferences] return top_n_recs @@ -699,10 +699,10 @@ def recommended_because(self, user_id, item_id, how_many=None, **params): else sorted_preferences if self.with_preference: - top_n_recs = np.array([(user_ids[ind], \ - prefs[ind]) for ind in sorted_preferences]) + top_n_recs = [(user_ids[ind], \ + prefs[ind]) for ind in sorted_preferences] else: - top_n_recs = np.array([user_ids[ind] - for ind in sorted_preferences]) + top_n_recs = [user_ids[ind] + for ind in sorted_preferences] return top_n_recs diff --git a/scikits/crab/recommenders/knn/tests/test_classes.py b/scikits/crab/recommenders/knn/tests/test_classes.py index 6a3b181..2e1930a 100644 --- a/scikits/crab/recommenders/knn/tests/test_classes.py +++ b/scikits/crab/recommenders/knn/tests/test_classes.py @@ -129,12 +129,12 @@ def test_estimate_preference_ItemBasedRecommender(): similarity = ItemSimilarity(boolean_matrix_model, jaccard_coefficient) recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy) assert_almost_equals(1.0, recsys.estimate_preference('Marcel Caraciolo', 'Superman Returns')) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) + assert_almost_equals(1.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) #With capper = False recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, False) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) + assert_almost_equals(1.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) #Non-Preferences - assert_array_equal(0.0, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree')) + assert_array_equal(np.NaN, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree')) def test_estimate_preference_UserBasedRecommender(): @@ -174,16 +174,16 @@ def test_estimate_preference_UserBasedRecommender(): similarity = UserSimilarity(boolean_matrix_model, jaccard_coefficient) recsys = UserBasedRecommender(boolean_matrix_model, similarity, nhood_strategy) assert_almost_equals(1.0, recsys.estimate_preference('Marcel Caraciolo', 'Superman Returns')) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) - assert_almost_equals(0.0, + assert_almost_equals(1.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) + assert_almost_equals(1.0, recsys.estimate_preference(user_id='Leopoldo Pires', item_id='You, Me and Dupree', distance=jaccard_coefficient, nhood_size=3)) #With capper = False recsys = UserBasedRecommender(boolean_matrix_model, similarity, nhood_strategy, False) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) + assert_almost_equals(1.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) #Non-Preferences - assert_array_equal(0.0, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree')) + assert_array_equal(np.NaN, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree')) def test_most_similar_items_ItemBasedRecommender(): @@ -240,15 +240,14 @@ def test_most_similar_users_UserBasedRecommender(): recsys.most_similar_users('Marcel Caraciolo', 4)) #all items assert_array_equal(np.array(['Lorena Abreu', 'Marcel Caraciolo', 'Penny Frewman', \ - 'Steve Gates', 'Luciana Nunes', 'Sheldom', 'Maria Gabriela']), \ + 'Steve Gates', 'Luciana Nunes', 'Sheldom']), \ recsys.most_similar_users('Leopoldo Pires')) #Non-existing - assert_array_equal(np.array(['Leopoldo Pires', 'Lorena Abreu', 'Luciana Nunes', - 'Marcel Caraciolo', 'Penny Frewman', 'Sheldom', 'Steve Gates']), \ + assert_array_equal(np.array([]), \ recsys.most_similar_users('Maria Gabriela')) #Exceed the limit assert_array_equal(np.array(['Lorena Abreu', 'Marcel Caraciolo', 'Penny Frewman', \ - 'Steve Gates', 'Luciana Nunes', 'Sheldom', 'Maria Gabriela']), \ + 'Steve Gates', 'Luciana Nunes', 'Sheldom']), \ recsys.most_similar_users('Leopoldo Pires', 20)) #Empty assert_array_equal(np.array([]), \ @@ -263,15 +262,14 @@ def test_most_similar_users_UserBasedRecommender(): recsys.most_similar_users('Marcel Caraciolo', 4)) #all items assert_array_equal(np.array(['Sheldom', 'Luciana Nunes', 'Marcel Caraciolo', - 'Steve Gates', 'Lorena Abreu', 'Penny Frewman', 'Maria Gabriela']), \ + 'Steve Gates', 'Lorena Abreu', 'Penny Frewman']), \ recsys.most_similar_users('Leopoldo Pires')) #Non-existing - assert_array_equal(np.array(['Leopoldo Pires', 'Lorena Abreu', 'Luciana Nunes', - 'Marcel Caraciolo', 'Penny Frewman', 'Sheldom', 'Steve Gates']), \ + assert_array_equal(np.array([]), \ recsys.most_similar_users('Maria Gabriela')) #Exceed the limit assert_array_equal(np.array(['Sheldom', 'Luciana Nunes', 'Marcel Caraciolo', - 'Steve Gates', 'Lorena Abreu', 'Penny Frewman', 'Maria Gabriela']), \ + 'Steve Gates', 'Lorena Abreu', 'Penny Frewman']), \ recsys.most_similar_users('Leopoldo Pires', 20)) #Empty assert_array_equal(np.array([]), \ @@ -304,10 +302,12 @@ def test_recommend_ItemBasedRecommender(): assert_array_equal(np.array([]), recsys.recommend('Maria Gabriela')) #with_preference - #recsys = ItemBasedRecommender(matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('Just My Luck', 3.20597319063), \ - # ('You, Me and Dupree', 3.14717875510)]), \ - # recsys.recommend('Leopoldo Pires')) + recsys = ItemBasedRecommender(matrix_model, similarity, items_strategy, True, True) + assert_equals('Just My Luck', recsys.recommend('Leopoldo Pires')[0][0]) + assert_equals('You, Me and Dupree', recsys.recommend('Leopoldo Pires')[1][0]) + + assert_almost_equals(3.20597, recsys.recommend('Leopoldo Pires')[0][1], 2) + assert_almost_equals(3.147178755, recsys.recommend('Leopoldo Pires')[1][1], 2) similarity = ItemSimilarity(boolean_matrix_model, jaccard_coefficient) #Empty Recommendation @@ -333,10 +333,12 @@ def test_recommend_ItemBasedRecommender(): assert_array_equal(np.array([]), recsys.recommend('Maria Gabriela')) #with_preference - #recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('Just My Luck', 3.20597), \ - # ('You, Me and Dupree', 3.1471)]), \ - # recsys.recommend('Leopoldo Pires')) + recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, True, True) + assert_equals('You, Me and Dupree', recsys.recommend('Leopoldo Pires')[0][0]) + assert_equals('Just My Luck', recsys.recommend('Leopoldo Pires')[1][0]) + + assert_almost_equals(1.0, recsys.recommend('Leopoldo Pires')[0][1], 2) + assert_almost_equals(1.0, recsys.recommend('Leopoldo Pires')[1][1], 2) def test_recommend_UserBasedRecommender(): @@ -365,10 +367,12 @@ def test_recommend_UserBasedRecommender(): assert_array_equal(np.array([]), recsys.recommend('Maria Gabriela')) #with_preference - #recsys = ItemBasedRecommender(matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('Just My Luck', 3.20597319063), \ - # ('You, Me and Dupree', 3.14717875510)]), \ - # recsys.recommend('Leopoldo Pires')) + recsys = UserBasedRecommender(matrix_model, similarity, nhood_strategy, True, True) + assert_equals('Just My Luck', recsys.recommend('Leopoldo Pires')[0][0]) + assert_equals('You, Me and Dupree', recsys.recommend('Leopoldo Pires')[1][0]) + + assert_almost_equals(2.456743361464, recsys.recommend('Leopoldo Pires')[0][1], 2) + assert_almost_equals(2.453379, recsys.recommend('Leopoldo Pires')[1][1], 2) similarity = UserSimilarity(boolean_matrix_model, jaccard_coefficient) #Empty Recommendation @@ -394,10 +398,12 @@ def test_recommend_UserBasedRecommender(): assert_array_equal(np.array([]), recsys.recommend('Maria Gabriela')) #with_preference - #recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('Just My Luck', 3.20597), \ - # ('You, Me and Dupree', 3.1471)]), \ - # recsys.recommend('Leopoldo Pires')) + recsys = UserBasedRecommender(boolean_matrix_model, similarity, nhood_strategy, True, True) + assert_equals('You, Me and Dupree', recsys.recommend('Leopoldo Pires')[0][0]) + assert_equals('Just My Luck', recsys.recommend('Leopoldo Pires')[1][0]) + + assert_almost_equals(1.0, recsys.recommend('Leopoldo Pires')[0][1], 2) + assert_almost_equals(1.0, recsys.recommend('Leopoldo Pires')[1][1], 2) def test_recommend_because_ItemBasedRecommender(): @@ -451,11 +457,6 @@ def test_recommend_because_ItemBasedRecommender(): assert_array_equal(np.array([]), \ recsys.recommended_because('Maria Gabriela', 'Just My Luck', 2)) - #with_preference - #recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('The Night Listener', 1.0), \ - # ('Superman Returns', 1.0)]), \ - # recsys.recommended_because('Leopoldo Pires', 'Just My Luck', 2)) def test_recommend_because_UserBasedRecommender(): @@ -508,10 +509,3 @@ def test_recommend_because_UserBasedRecommender(): recsys = UserBasedRecommender(boolean_matrix_model, similarity, nhood_strategy) assert_array_equal(np.array([]), \ recsys.recommended_because('Maria Gabriela', 'Just My Luck', 2)) - - #with_preference - #recsys = ItemBasedRecommender(boolean_matrix_model, similarity, items_strategy, True, True) - #assert_array_equal(np.array([('The Night Listener', 1.0), \ - # ('Superman Returns', 1.0)]), \ - # recsys.recommended_because('Leopoldo Pires', 'Just My Luck', 2)) - diff --git a/scikits/crab/recommenders/svd/classes.py b/scikits/crab/recommenders/svd/classes.py index e8dd227..24de9b7 100644 --- a/scikits/crab/recommenders/svd/classes.py +++ b/scikits/crab/recommenders/svd/classes.py @@ -135,8 +135,8 @@ class MatrixFactorBasedRecommender(SVDRecommender): n_features=2) >>> #Return the recommendations for the given user. >>> recsys.recommend('Leopoldo Pires') - array(['Just My Luck', 'You, Me and Dupree'],\ - dtype='|S18') + ['Just My Luck', 'You, Me and Dupree'] + Notes ----------- @@ -383,10 +383,10 @@ def _top_matches(self, source_id, target_ids, how_many=None, **params): else sorted_preferences if self.with_preference: - top_n_recs = np.array([(target_ids[ind], \ - preferences[ind]) for ind in sorted_preferences]) + top_n_recs = [(target_ids[ind], \ + preferences[ind]) for ind in sorted_preferences] else: - top_n_recs = np.array([target_ids[ind] - for ind in sorted_preferences]) + top_n_recs = [target_ids[ind] + for ind in sorted_preferences] return top_n_recs diff --git a/scikits/crab/recommenders/svd/tests/test_classes.py b/scikits/crab/recommenders/svd/tests/test_classes.py index 2147236..02215b4 100644 --- a/scikits/crab/recommenders/svd/tests/test_classes.py +++ b/scikits/crab/recommenders/svd/tests/test_classes.py @@ -143,18 +143,18 @@ def test_estimate_preference_MatrixFactorBasedRecommender(): items_selection_strategy=items_strategy, n_features=2) assert_almost_equals(1.0, recsys.estimate_preference('Marcel Caraciolo', 'Superman Returns')) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) - assert_almost_equals(0.0, - recsys.estimate_preference(user_id='Leopoldo Pires', item_id='You, Me and Dupree')) + assert_almost_equals(0.72, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree'), 1) + assert_almost_equals(0.73, + recsys.estimate_preference(user_id='Leopoldo Pires', item_id='You, Me and Dupree'), 1) #With capper = False recsys = MatrixFactorBasedRecommender( model=boolean_matrix_model, items_selection_strategy=items_strategy, n_features=2, capper=False) - assert_almost_equals(0.0, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree')) + assert_almost_equals(0.73, recsys.estimate_preference('Leopoldo Pires', 'You, Me and Dupree'), 1) #Non-Preferences - assert_array_equal(0.0, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree')) + assert_almost_equals(0.7258, recsys.estimate_preference('Maria Gabriela', 'You, Me and Dupree'), 1) def test_recommend_MatrixFactorBasedRecommender(): @@ -210,7 +210,7 @@ def test_recommend_MatrixFactorBasedRecommender(): model=boolean_matrix_model, items_selection_strategy=items_strategy, n_features=2) - assert_array_equal(np.array(['You, Me and Dupree', 'Just My Luck']), \ + assert_array_equal(np.array(['Just My Luck', 'You, Me and Dupree']), \ recsys.recommend('Leopoldo Pires')) #Semi Recommendation diff --git a/setup.py b/setup.py index cac560d..43b0a7b 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,8 @@ MAINTAINER_EMAIL = 'marcel@muricoca.com', URL = 'http://muricoca.github.com/crab/' LICENSE = 'new BSD' -DOWNLOAD_URL = "http://pypi.python.org/pypi/scikits.crab" -VERSION = '0.0.1' +DOWNLOAD_URL = "http://pypi.python.org/pypi/crab" +VERSION = '0.1' from numpy.distutils.core import setup @@ -44,6 +44,7 @@ def configuration(parent_package='', top_path=None): setup(configuration=configuration, name=DISTNAME, version=VERSION, + include_package_data=True, install_requires='numpy', namespace_packages=['scikits'], maintainer=MAINTAINER, @@ -53,9 +54,17 @@ def configuration(parent_package='', top_path=None): url=URL, download_url=DOWNLOAD_URL, long_description=LONG_DESCRIPTION, - classifiers=['Development Status :: 1 - Planning', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: BSD License', - 'Topic :: Scientific/Engineering']) + zip_safe=False, # the package can run out of an .egg file + classifiers=[ + 'Intended Audience :: Science/Research', + 'Intended Audience :: Developers', + 'License :: OSI Approved', + 'Programming Language :: C', + 'Programming Language :: Python', + 'Topic :: Software Development', + 'Topic :: Scientific/Engineering', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Operating System :: MacOS' + ])