public override double GetEvaluation(IDictionary<User, ICollection<Preference>> testUserPrefs,
		                     Recommender recommender)
		{
			RunningAverage average = new FullRunningAverage();
			foreach (KeyValuePair<User, ICollection<Preference>> entry in testUserPrefs) 
			{
				foreach (Preference realPref in entry.Value) 
				{
					User testUser = entry.Key;
					try 
					{
						double estimatedPreference =
							recommender.EstimatePreference(testUser.ID, realPref.Item.ID);
						if (!double.IsNaN(estimatedPreference)) 
						{
							double diff = realPref.Value - estimatedPreference;
							average.AddDatum(diff * diff);
						}
					} 
                    catch (NoSuchElementException nsee) 
                    {
						// It's possible that an item exists in the test data but not training data in which case
						// NSEE will be thrown. Just ignore it and move on.
						log.Info("Element exists in test data but not training data: " + testUser.ID, nsee);
					}
				}
			}
			return Math.Sqrt(average.Average);
		}
        public override double GetEvaluation(IDictionary <User, ICollection <Preference> > testUserPrefs,
                                             Recommender recommender)
        {
            RunningAverage average = new FullRunningAverage();

            foreach (KeyValuePair <User, ICollection <Preference> > entry in testUserPrefs)
            {
                foreach (Preference realPref in entry.Value)
                {
                    User testUser = entry.Key;
                    try
                    {
                        double estimatedPreference =
                            recommender.EstimatePreference(testUser.ID, realPref.Item.ID);
                        if (!double.IsNaN(estimatedPreference))
                        {
                            double diff = realPref.Value - estimatedPreference;
                            average.AddDatum(diff * diff);
                        }
                    }
                    catch (NoSuchElementException nsee)
                    {
                        // It's possible that an item exists in the test data but not training data in which case
                        // NSEE will be thrown. Just ignore it and move on.
                        log.Info("Element exists in test data but not training data: " + testUser.ID, nsee);
                    }
                }
            }
            return(Math.Sqrt(average.Average));
        }
            public Double GetValue(Pair <object, object> key)
            {
                Object userID = key.First;
                Object itemID = key.Second;

                if (log.IsDebugEnabled)
                {
                    log.Debug("Retrieving estimated preference for user ID '" + userID + "\' and item ID \'" +
                              itemID.ToString() + '\'');
                }
                return(recommender.EstimatePreference(userID, itemID));
            }
Exemple #4
0
        public void TestEstimatePref()
        {
            Recommender recommender = buildRecommender();

            Assert.AreEqual(0.3, recommender.EstimatePreference("test1", "2"));
        }
        public void TestEstimatePref()
        {
            Recommender recommender = buildRecommender();

            Assert.AreEqual(0.34803885284992736, recommender.EstimatePreference("test1", "2"), EPSILON);
        }