Skip to content

Commit

Permalink
Add rank size in rating prediction evaluation; New Version
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfortes committed Jun 25, 2018
1 parent 5d091a3 commit 6a141a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions caserec/evaluation/rating_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class RatingPredictionEvaluation(BaseEvaluation):
def __init__(self, sep='\t', metrics=list(['MAE', 'RMSE']), all_but_one_eval=False, verbose=True, as_table=False,
table_sep='\t', as_rank=False):
table_sep='\t', as_rank=False, n_rank=10):
"""
Class to evaluate predictions in a rating prediction scenario
Expand Down Expand Up @@ -54,6 +54,7 @@ def __init__(self, sep='\t', metrics=list(['MAE', 'RMSE']), all_but_one_eval=Fal
super(RatingPredictionEvaluation, self).__init__(sep=sep, metrics=metrics, all_but_one_eval=all_but_one_eval,
verbose=verbose, as_table=as_table, table_sep=table_sep)
self.as_rank = as_rank
self.n_rank = n_rank

def evaluate(self, predictions, test_set):
"""
Expand Down Expand Up @@ -102,7 +103,6 @@ def evaluate(self, predictions, test_set):
else:
new_predict_set = []
new_test_set = {}
high_len_rank = 0

for user in predictions:
partial_predictions = []
Expand All @@ -117,13 +117,10 @@ def evaluate(self, predictions, test_set):
partial_predictions = sorted(partial_predictions, key=lambda x: -x[2])
new_predict_set += partial_predictions

if high_len_rank < len(partial_predictions):
high_len_rank = len(partial_predictions)

new_test_set['items_seen_by_user'] = new_test_set
new_test_set['users'] = test_set['users']

ItemRecommendationEvaluation(n_ranks=[high_len_rank],
ItemRecommendationEvaluation(n_ranks=self.n_rank,
all_but_one_eval=self.all_but_one_eval).evaluate_recommender(
new_predict_set, new_test_set)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
setup(
name='CaseRecommender',
packages=find_packages(),
version='1.0.11',
version='1.0.12',
license='MIT License',
description='A recommender systems framework for Python',
long_description=long_description,
Expand Down

0 comments on commit 6a141a8

Please sign in to comment.