Bi-polar frequency-weighted Slope-One rating prediction
Daniel Lemire, Anna Maclachlan: Slope One Predictors for Online Rating-Based Collaborative Filtering. SIAM Data Mining (SDM 2005) http://www.daniel-lemire.com/fr/abstracts/SDM2005.html This recommender does NOT support incremental updates. They would be easy to implement, though.
Inheritance: RatingPredictor
示例#1
0
        public static List<Movie> GetRecommendations(List<Movie> all, Dictionary<int, int> newRanks, List<Tuple<int, int, float>> oldRanks)
        {
            int newUserId = 0;
            Ratings ratings = new Ratings();

            foreach (var r in oldRanks)
            {
                ratings.Add(r.Item1, r.Item2, r.Item3);
                if (r.Item1 > newUserId) newUserId = r.Item1;
            }

            // this makes us sure that the new user has a unique id (bigger than all other)
            newUserId = newUserId + 1;

            foreach (var k in newRanks)
            {
                ratings.Add(newUserId, k.Key, (float)k.Value);
            }

            var engine = new BiPolarSlopeOne();

            // different algorithm:
            // var engine = new UserItemBaseline();

            engine.Ratings = ratings;

            engine.Train(); // warning: this could take some time!

            return all.Select(m =>
                                {
                                    m.Rank = engine.Predict(newUserId, m.Id); // do the prediction!
                                    return m;
                                }).ToList();
        }
示例#2
0
        public void TestNewUserInTestSet()
        {
            var recommender = new BiPolarSlopeOne();

            var training_data = new Ratings();
            training_data.Add(0, 0, 1.0f);
            training_data.Add(1, 1, 5.0f);

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual( 3.0, recommender.Predict(2, 1) );
        }
        public void TestNewItemInTestSet()
        {
            var recommender = new BiPolarSlopeOne();
            recommender.MinRating = 1;
            recommender.MaxRating = 5;

            var training_data = new Ratings();
            training_data.Add(0, 0, 1.0);
            training_data.Add(1, 1, 5.0);

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual( 3.0, recommender.Predict(0, 2) );
        }