public void testFullCorrelation1Weighted() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{3.0, -2.0}, new double?[]{3.0, -2.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2); assertCorrelationEquals(1.0, correlation); }
public void testFullCorrelation1() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 3.0, -2.0 }, new double?[] { 3.0, -2.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); assertCorrelationEquals(1.0, correlation); }
public void testNoCorrelation1Weighted() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 3.0, -2.0 }, new double?[] { -3.0, 2.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2); assertCorrelationEquals(-1.0, correlation); }
public void testNoCorrelation3() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 90.0, 80.0, 70.0 }, new double?[] { 70.0, 80.0, 90.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); assertCorrelationEquals(-1.0, correlation); }
public void testFullCorrelation2() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{3.0, 3.0}, new double?[]{3.0, 3.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); // Yeah, undefined in this case Assert.True(Double.IsNaN(correlation)); }
public void testSimple() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 1.0, 2.0, 3.0 }, new double?[] { 2.0, 5.0, 6.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); assertCorrelationEquals(0.9607689228305227, correlation); }
public void testSimpleWeighted() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 1.0, 2.0, 3.0 }, new double?[] { 2.0, 5.0, 6.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2); assertCorrelationEquals(0.9901922307076306, correlation); }
public void testNoCorrelation2() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { null, 1.0, null }, new double?[] { null, null, 1.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); Assert.True(Double.IsNaN(correlation)); }
public void testNoItemCorrelation1() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 3.0, -3.0 }, new double?[] { 2.0, -2.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).ItemSimilarity(0, 1); assertCorrelationEquals(-1.0, correlation); }
public void testFullCorrelation2() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { 3.0, 3.0 }, new double?[] { 3.0, 3.0 }, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); // Yeah, undefined in this case Assert.True(Double.IsNaN(correlation)); }
public void testSimpleItemWeighted() { IDataModel dataModel = getDataModel( new long[] { 1, 2, 3 }, new Double?[][] { new double?[] { 1.0, 2.0 }, new double?[] { 2.0, 5.0 }, new double?[] { 3.0, 6.0 }, }); IItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED); double correlation = itemSimilarity.ItemSimilarity(0, 1); assertCorrelationEquals(0.9901922307076306, correlation); }
public Result RecommendPearsonCorrelationSimilarity(int userId, int movieId) { Result result = new Result(); dataModel = new FileDataModel(PathToDataFile, false, FileDataModel.DEFAULT_MIN_RELOAD_INTERVAL_MS, false, ",", userId, movieId); var removedPrefs = GenericDataModel.preferenceFromUsersRemoved.Values; var valueToCompare = removedPrefs.FirstOrDefault(i => i.GetItemID() == movieId).GetValue(); var similarity = new PearsonCorrelationSimilarity(dataModel); var recommender = new GenericItemBasedRecommender(dataModel, similarity); var preferences = recommender.EstimatePreference(userId, movieId); result.PredictedValue = preferences; result.RealValue = removedPrefs.First().GetValue(); return result; }
public void testFromCorrelation() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double?[][] { new double?[] {1.0, 2.0}, new double?[] {2.0, 5.0}, new double?[] {3.0, 6.0}, }); IItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel); IItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel); assertCorrelationEquals(1.0, itemSimilarity.ItemSimilarity(0, 0)); assertCorrelationEquals(0.960768922830523, itemSimilarity.ItemSimilarity(0, 1)); }
public void testInferrer() { IDataModel dataModel = getDataModel( new long[] { 1, 2 }, new Double?[][] { new double?[] { null, 1.0, 2.0, null, null, 6.0 }, new double?[] { 1.0, 8.0, null, 3.0, 4.0, null }, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); similarity.SetPreferenceInferrer(new TestPreferenceInferrer()); Assert.AreEqual(-0.435285750066007, similarity.UserSimilarity(1L, 2L), EPSILON); }
public void testFromCorrelation() { IDataModel dataModel = getDataModel( new long[] { 1, 2, 3 }, new Double?[][] { new double?[] { 1.0, 2.0 }, new double?[] { 2.0, 5.0 }, new double?[] { 3.0, 6.0 }, }); IItemSimilarity otherSimilarity = new PearsonCorrelationSimilarity(dataModel); IItemSimilarity itemSimilarity = new GenericItemSimilarity(otherSimilarity, dataModel); assertCorrelationEquals(1.0, itemSimilarity.ItemSimilarity(0, 0)); assertCorrelationEquals(0.960768922830523, itemSimilarity.ItemSimilarity(0, 1)); }
public void testHowMany() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3, 4, 5}, new Double?[][] { new double?[]{0.1, 0.2}, new double?[]{0.2, 0.3, 0.3, 0.6}, new double?[]{0.4, 0.4, 0.5, 0.9}, new double?[]{0.1, 0.4, 0.5, 0.8, 0.9, 1.0}, new double?[]{0.2, 0.3, 0.6, 0.7, 0.1, 0.2}, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel); IRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); IList<IRecommendedItem> fewRecommended = recommender.Recommend(1, 2); IList<IRecommendedItem> moreRecommended = recommender.Recommend(1, 4); for (int i = 0; i < fewRecommended.Count; i++) { Assert.AreEqual(fewRecommended[i].GetItemID(), moreRecommended[i].GetItemID()); } recommender.Refresh(null); for (int i = 0; i < fewRecommended.Count; i++) { Assert.AreEqual(fewRecommended[i].GetItemID(), moreRecommended[i].GetItemID()); } }
public void testSimpleItem() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double?[][] { new double?[]{1.0, 2.0}, new double?[]{2.0, 5.0}, new double?[]{3.0, 6.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).ItemSimilarity(0, 1); assertCorrelationEquals(0.9607689228305227, correlation); }
public void testSimpleItemWeighted() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double?[][] { new double?[]{1.0, 2.0}, new double?[]{2.0, 5.0}, new double?[]{3.0, 6.0}, }); IItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED); double correlation = itemSimilarity.ItemSimilarity(0, 1); assertCorrelationEquals(0.9901922307076306, correlation); }
public void testSimpleWeighted() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{1.0, 2.0, 3.0}, new double?[]{2.0, 5.0, 6.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel, Weighting.WEIGHTED).UserSimilarity(1, 2); assertCorrelationEquals(0.9901922307076306, correlation); }
public void testNoCorrelation1() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{3.0, -2.0}, new double?[]{-3.0, 2.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).UserSimilarity(1, 2); assertCorrelationEquals(-1.0, correlation); }
public void testFullItemCorrelation1() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{3.0, 3.0}, new double?[]{-2.0, -2.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).ItemSimilarity(0, 1); assertCorrelationEquals(1.0, correlation); }
public void testNoItemCorrelation3() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double?[][] { new double?[]{90.0, 70.0}, new double?[]{80.0, 80.0}, new double?[]{70.0, 90.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).ItemSimilarity(0, 1); assertCorrelationEquals(-1.0, correlation); }
private static IUserBasedRecommender buildRecommender() { IDataModel dataModel = getDataModel(); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel); return new GenericUserBasedRecommender(dataModel, neighborhood, similarity); }
public void testRescorer() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3}, new Double?[][] { new double?[]{0.1, 0.2}, new double?[]{0.2, 0.3, 0.3, 0.6}, new double?[]{0.4, 0.5, 0.5, 0.9}, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel); IRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); IList<IRecommendedItem> originalRecommended = recommender.Recommend(1, 2); IList<IRecommendedItem> rescoredRecommended = recommender.Recommend(1, 2, new ReversingRescorer<long>()); Assert.NotNull(originalRecommended); Assert.NotNull(rescoredRecommended); Assert.AreEqual(2, originalRecommended.Count); Assert.AreEqual(2, rescoredRecommended.Count); Assert.AreEqual(originalRecommended[0].GetItemID(), rescoredRecommended[1].GetItemID()); Assert.AreEqual(originalRecommended[1].GetItemID(), rescoredRecommended[0].GetItemID()); }
public void testInferrer() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{null, 1.0, 2.0, null, null, 6.0}, new double?[]{1.0, 8.0, null, 3.0, 4.0, null}, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); similarity.SetPreferenceInferrer(new TestPreferenceInferrer()); Assert.AreEqual(-0.435285750066007, similarity.UserSimilarity(1L, 2L), EPSILON); }
public void testNoItemCorrelation2() { IDataModel dataModel = getDataModel( new long[] {1, 2}, new Double?[][] { new double?[]{null, 1.0, null}, new double?[]{null, null, 1.0}, }); double correlation = new PearsonCorrelationSimilarity(dataModel).ItemSimilarity(1, 2); Assert.True(Double.IsNaN(correlation)); }
public void testIsolatedUser() { IDataModel dataModel = getDataModel( new long[] {1, 2, 3, 4}, new Double?[][] { new double?[]{0.1, 0.2}, new double?[]{0.2, 0.3, 0.3, 0.6}, new double?[]{0.4, 0.4, 0.5, 0.9}, new double?[]{null, null, null, null, 1.0}, }); IUserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(3, similarity, dataModel); IUserBasedRecommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity); long[] mostSimilar = recommender.MostSimilarUserIDs(4, 3); Assert.NotNull(mostSimilar); Assert.AreEqual(0, mostSimilar.Length); }
public void testFile() { IUserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model); IUserNeighborhood neighborhood = new NearestNUserNeighborhood(3, userSimilarity, model); IRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity); Assert.AreEqual(1, recommender.Recommend(123, 3).Count); Assert.AreEqual(0, recommender.Recommend(234, 3).Count); Assert.AreEqual(1, recommender.Recommend(345, 3).Count); // Make sure this doesn't throw an exception model.Refresh(null); }