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(); }
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) ); }