Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 def test_users(self):
     profiler = sequeval.Profiler(sequences)
     self.assertEqual(2, profiler.users())
Ejemplo n.º 3
0
 def test_sequence_length(self):
     profiler = sequeval.Profiler(sequences)
     self.assertAlmostEqual(8 / 3, profiler.sequence_length())
Ejemplo n.º 4
0
 def test_sparsity(self):
     profiler = sequeval.Profiler(sequences)
     self.assertAlmostEqual(8 / 9, profiler.sparsity())
Ejemplo n.º 5
0
 def test_sequences(self):
     profiler = sequeval.Profiler(sequences)
     self.assertEqual(3, profiler.sequences())
Ejemplo n.º 6
0
 def test_ratings(self):
     profiler = sequeval.Profiler(sequences)
     self.assertEqual(8, profiler.ratings())
Ejemplo n.º 7
0
    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':
        print("\n# Random splitter")
        splitter = sequeval.RandomSplitter(args.ratio)
    elif args.splitter == 'timestamp':
        print("\n# Timestamp splitter")
        splitter = sequeval.TimestampSplitter(args.ratio)
    else:
        raise RuntimeError('Unknown splitter ' + args.splitter)