/// <summary> /// Predict the rating of the item by users /// </summary> private static void PredictRating(string[] args) { Console.WriteLine("Predicting ratings for Users..."); String outputFile = Path.Combine(args[2], outputFileForRatings); testingFile = Path.Combine(args[1], testingFile); testingFileModified = Path.Combine(args[2], testingFileModified); ModifyTestingFileForRating(testingFile, testingFileModified); float minRating = 1; float maxRating = 5; var userMapping = new Mapping(); var itemMapping = new Mapping(); var trainingData = StaticRatingData.Read(trainingCompactFileForRatings, userMapping, itemMapping, RatingType.FLOAT, TestRatingFileFormat.WITH_RATINGS, false); var testUsers = trainingData.AllUsers; // users that will be taken into account in the evaluation var candidate_items = trainingData.AllItems; // items that will be taken into account in the evaluation var testData = StaticRatingData.Read(testingFileModified, userMapping, itemMapping, RatingType.FLOAT, TestRatingFileFormat.WITH_RATINGS, false); var recommender = new BiasedMatrixFactorization(); recommender.MinRating = minRating; recommender.MaxRating = maxRating; recommender.Ratings = trainingData; recommender.NumFactors = 30; recommender.NumIter = 100; recommender.RegI = 0.04F; recommender.RegU = 0.04F; //recommender.BiasReg = 0.09F; recommender.FrequencyRegularization = true; recommender.BoldDriver = true; recommender.LearnRate = 0.07F; Stopwatch timeKeeper = new Stopwatch(); timeKeeper.Start(); recommender.Train(); timeKeeper.Stop(); Console.WriteLine("time passed for training rating prediction model: " + timeKeeper.ElapsedMilliseconds); // measure the accuracy on the test data set timeKeeper = new Stopwatch(); timeKeeper.Start(); var results = recommender.Evaluate(testData); timeKeeper.Stop(); Console.WriteLine("time passed for rating prediction: " + timeKeeper.ElapsedMilliseconds); Console.WriteLine("RMSE={0}", results["RMSE"]); recommender.WritePredictions(testData, outputFile, userMapping, itemMapping, "{0}-{1},{2}", "userID-itemID,rating"); }
public void TestRead() { var reader = new StringReader(@"5951,50,5,2001-01-01 5951,223,5,2001-01-01 5951,260,5,2001-01-01 5951,293,5,2001-01-01 5951,356,4,2001-01-01 5951,364,3,2001-01-01 5951,457,3,2001-01-01 "); IRatings data = StaticRatingData.Read(reader, 7); Assert.AreEqual(7, data.Count); }
public void TestReadIgnoreLine() { var reader = new StringReader(@"# first line 5951,50,5,2001-01-01 00:00:00 5951,223,5,2001-01-01 00:00:00 5951,260,5,2001-01-01 00:00:00 5951,293,5,2001-01-01 00:00:00 5951,356,4,2001-01-01 00:00:00 5951,364,3,2001-01-01 00:00:00 5951,457,3,2001-01-01 00:00:00 "); IRatings data = StaticRatingData.Read(reader, 7, null, null, RatingType.FLOAT, TestRatingFileFormat.WITH_RATINGS, true); Assert.AreEqual(7, data.Count); }
protected override void LoadData() { bool static_data = !online_eval; TimeSpan loading_time = Wrap.MeasureTime(delegate() { base.LoadData(); // read training data if ((recommender is TimeAwareRatingPredictor || chronological_split != null) && file_format != RatingFileFormat.MOVIELENS_1M) { training_data = TimedRatingData.Read(training_file, user_mapping, item_mapping); } else { if (file_format == RatingFileFormat.DEFAULT) { training_data = static_data ? StaticRatingData.Read(training_file, user_mapping, item_mapping, rating_type) : RatingData.Read(training_file, user_mapping, item_mapping); } else if (file_format == RatingFileFormat.IGNORE_FIRST_LINE) { training_data = static_data ? StaticRatingData.Read(training_file, user_mapping, item_mapping, rating_type, TestRatingFileFormat.WITH_RATINGS, true) : RatingData.Read(training_file, user_mapping, item_mapping, true); } else if (file_format == RatingFileFormat.MOVIELENS_1M) { training_data = MovieLensRatingData.Read(training_file, user_mapping, item_mapping); } else if (file_format == RatingFileFormat.KDDCUP_2011) { training_data = MyMediaLite.IO.KDDCup2011.Ratings.Read(training_file); } } recommender.Ratings = training_data; // read test data if (test_file != null) { TestRatingFileFormat test_format = test_no_ratings ? TestRatingFileFormat.WITHOUT_RATINGS : TestRatingFileFormat.WITH_RATINGS; if (recommender is TimeAwareRatingPredictor && file_format != RatingFileFormat.MOVIELENS_1M) { test_data = TimedRatingData.Read(test_file, user_mapping, item_mapping, test_format); } else if (file_format == RatingFileFormat.MOVIELENS_1M) { test_data = MovieLensRatingData.Read(test_file, user_mapping, item_mapping, test_format); } else if (file_format == RatingFileFormat.KDDCUP_2011) { test_data = MyMediaLite.IO.KDDCup2011.Ratings.Read(test_file); } else { test_data = StaticRatingData.Read(test_file, user_mapping, item_mapping, rating_type, test_format, file_format == RatingFileFormat.IGNORE_FIRST_LINE); } if (recommender is ITransductiveRatingPredictor) { ((ITransductiveRatingPredictor)recommender).AdditionalFeedback = test_data; } } }); Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "loading_time {0:0.##}", loading_time.TotalSeconds)); Console.Error.WriteLine("memory {0}", Memory.Usage); }