static void Assignment3() { RecommenderSystem rs = new RecommenderSystem(); rs.Load("ratings.dat", 0.97); //rs.TrainBaseModel(10); //rs.TrainStereotypes(10); string testUserId = rs.getTestUserId(); //List<string> lRecommendationsCp = rs.Recommend(RecommenderSystem.RecommendationMethod.CP, testUserId, 5); //List<string> lRecommendationsJaccard = rs.Recommend(RecommenderSystem.RecommendationMethod.Jaccard, testUserId, 5); //List<string> lRecommendations = rs.Recommend(RecommenderSystem.RecommendationMethod.Pearson, "6", 5); //Console.Write("Recommended movies for user 6 "); //foreach (string sMovie in lRecommendations) // Console.Write(sMovie + ","); //Console.WriteLine(); // //List<string> lRecommendationsPopulairty = rs.Recommend(RecommenderSystem.RecommendationMethod.Popularity, "2", 5); //List<string> lRecommendationsPearson = rs.Recommend(RecommenderSystem.RecommendationMethod.Pearson, "2", 5); //List<string> lRecommendationsCosine = rs.Recommend(RecommenderSystem.RecommendationMethod.Cosine, "2", 5); //List<string> lRecommendationsBaseModel = rs.Recommend(RecommenderSystem.RecommendationMethod.BaseModel, "2", 5); //List<string> lRecommendationsSt = rs.Recommend(RecommenderSystem.RecommendationMethod.Stereotypes, "2", 5); // List <RecommenderSystem.RecommendationMethod> lMethods = new List <RecommenderSystem.RecommendationMethod>(); //List<RecommenderSystem.RecommendationMethod> lMethods = new List<RecommenderSystem.RecommendationMethod>(); lMethods.Add(RecommenderSystem.RecommendationMethod.Jaccard); lMethods.Add(RecommenderSystem.RecommendationMethod.CP); // List <int> lLengths = new List <int>(); lLengths.Add(1); lLengths.Add(3); lLengths.Add(5); lLengths.Add(10); lLengths.Add(20); DateTime dtStart = DateTime.Now; Dictionary <int, Dictionary <RecommenderSystem.RecommendationMethod, Dictionary <string, double> > > dResults = rs.ComputePrecisionRecall(lMethods, lLengths, 1000); Console.WriteLine("Precision-recall scores for all methods are:"); foreach (int iLength in lLengths) { foreach (RecommenderSystem.RecommendationMethod sMethod in lMethods) { foreach (string sMetric in dResults[iLength][sMethod].Keys) { Console.WriteLine(iLength + "," + sMethod + "," + sMetric + " = " + Math.Round(dResults[iLength][sMethod][sMetric], 4)); } } } Console.WriteLine("Execution time was " + Math.Round((DateTime.Now - dtStart).TotalSeconds, 0)); Console.ReadLine(); }
static void Assignment2() { RecommenderSystem rs = new RecommenderSystem(); rs.Load("Dating/ratings.dat", 0.95); rs.TrainBaseModel(10); Console.WriteLine("Real rating of user 1 to item 133 using SVD is " + Math.Round(rs.GetRating("1", "133"), 4)); Console.WriteLine("Predicted rating of user 1 to item 133 using SVD is " + Math.Round(rs.PredictRating(RecommenderSystem.PredictionMethod.SVD, "1", "133"), 4)); List <RecommenderSystem.PredictionMethod> lMethods = new List <RecommenderSystem.PredictionMethod>(); lMethods.Add(RecommenderSystem.PredictionMethod.SVD); lMethods.Add(RecommenderSystem.PredictionMethod.Pearson); lMethods.Add(RecommenderSystem.PredictionMethod.Cosine); lMethods.Add(RecommenderSystem.PredictionMethod.Random); DateTime dtStart = DateTime.Now; Dictionary <RecommenderSystem.PredictionMethod, Dictionary <RecommenderSystem.PredictionMethod, double> > dConfidence = null; Dictionary <RecommenderSystem.PredictionMethod, double> dResults = rs.ComputeRMSE(lMethods, out dConfidence); Console.WriteLine("Hit ratio scores for Pearson, Cosine, SVD, and Random are:"); foreach (KeyValuePair <RecommenderSystem.PredictionMethod, double> p in dResults) { Console.Write(p.Key + "=" + Math.Round(p.Value, 4) + ", "); } Console.WriteLine("Confidence P-values are:"); foreach (RecommenderSystem.PredictionMethod sFirst in dConfidence.Keys) { foreach (RecommenderSystem.PredictionMethod sSecond in dConfidence[sFirst].Keys) { Console.WriteLine("p(" + sFirst + "=" + sSecond + ")=" + dConfidence[sFirst][sSecond].ToString("F3")); } } Console.WriteLine(); Console.WriteLine("Execution time was " + Math.Round((DateTime.Now - dtStart).TotalSeconds, 0)); Console.ReadLine(); }