def run(): _user_ratings = int(request.args.get('user-ratings')) _item_ratings = int(request.args.get('item-ratings')) _splitter = request.args.get('splitter') _ratio = float(request.args.get('ratio')) / 100 _k = int(request.args.get('length')) loader = sequeval.UIRTLoader(user_ratings=_user_ratings, item_ratings=_item_ratings) ratings = loader.load('datasets/yes_reduced.csv') builder = sequeval.Builder('1000 s') sequences, items = builder.build(ratings) profiler = sequeval.Profiler(sequences) response = { 'profiler': { 'users': profiler.users(), 'items': profiler.items(), 'ratings': profiler.ratings(), 'sequences': profiler.sequences(), 'sparsity': parse(profiler.sparsity()), 'length': parse(profiler.sequence_length()) } } if _splitter == 'random': splitter = sequeval.RandomSplitter(_ratio) else: splitter = sequeval.TimestampSplitter(_ratio) training_set, test_set = splitter.split(sequences) response['splitter'] = { 'training': len(training_set), 'test': len(test_set) } evaluator = sequeval.Evaluator(training_set, test_set, items, _k) cosine = sequeval.CosineSimilarity(training_set, items) response['evaluator'] = [] most_popular = baseline.MostPopularRecommender(training_set, items) response['evaluator'].append(evaluation(evaluator, most_popular, cosine)) random = baseline.RandomRecommender(training_set, items) response['evaluator'].append(evaluation(evaluator, random, cosine)) unigram = baseline.UnigramRecommender(training_set, items) response['evaluator'].append(evaluation(evaluator, unigram, cosine)) bigram = baseline.BigramRecommender(training_set, items) response['evaluator'].append(evaluation(evaluator, bigram, cosine)) return json.dumps(response)
print("\n# Parameters") print("File:", args.file) print("Seed:", args.seed) print("User ratings:", args.user) print("Item ratings:", args.item) print("Delta:", args.delta) print("Ratio:", args.ratio) print("Length:", args.length) # Set the random seed if args.seed is not None: random.seed(args.seed) np.random.seed(args.seed) loader = sequeval.UIRTLoader(user_ratings=args.user, item_ratings=args.item) ratings = loader.load(args.file) builder = sequeval.Builder(args.delta) sequences, items = builder.build(ratings) print("\n# Profiler") profiler = sequeval.Profiler(sequences) print("Users:", profiler.users()) print("Items:", profiler.items()) print("Ratings:", profiler.ratings()) print("Sequences:", profiler.sequences()) print("Sparsity:", profiler.sparsity()) print("Length:", profiler.sequence_length()) if args.splitter == 'random':
def test_uirt_threshold(self): fake_input = "1,1,5,0\n1,2,5,5\n1,1,5,10\n1,3,5,30\n1,2,5,35,\n2,1,5,5\n2,1,5,30\n2,2,5,35\n2,2,2,40" loader = sequeval.UIRTLoader(threshold=3) self.assertEqual(ratings[0:8], loader.load(io.StringIO(fake_input)))
def test_uirt_skip(self): fake_input = "1,1,5,0\n1,2,5,5\n1,1,5,10\n1,3,5,30\n1,2,5,35,\n2,1,5,5\n2,1,5,30\n2,2,5,35\n2,2,5,40" loader = sequeval.UIRTLoader(skip=1) self.assertEqual(ratings[1:], loader.load(io.StringIO(fake_input)))
def test_uirt_item_ratings(self): fake_input = "1,1,5,0\n1,2,5,5\n1,1,5,10\n1,3,5,30\n1,2,5,35,\n2,1,5,5\n2,1,5,30\n2,2,5,35\n2,2,5,40" loader = sequeval.UIRTLoader(item_ratings=2) self.assertEqual(ratings[:3] + ratings[4:], loader.load(io.StringIO(fake_input)))