private void RunRatingPrediction() { // step 1: dataset Dataset <ItemRating> dataset; if (Parameters.GetValueOrDefault("data-format", "") == "crowdrec") { string efile = Parameters.GetValueOrDefault("entitiesfile", ""); string rfile = Parameters.GetValueOrDefault("relationsfile", ""); if (efile == "" || rfile == "") { throw new WrapRecException("The parameters 'entitesfile' and 'relationsfile' should be specified."); } var reader = new CrowdRecDataReader(efile, rfile); var container = new CrowdRecDataContainer(); reader.LoadData(container); if (Parameters.GetValueOrDefault("testportion", "") == "") { throw new WrapRecException("The parameter 'testportion' should be specified."); } dataset = new ItemRatingDataset(container, float.Parse(Parameters["testportion"])); } else if (Parameters.GetValueOrDefault("dataset", "") != "") { dataset = GetDataset <ItemRating>(Parameters["dataset"], "", new ItemRatingMap()); } else if (Parameters.GetValueOrDefault("trainfile", "") != "" && Parameters.GetValueOrDefault("testfile", "") != "") { dataset = GetDataset <ItemRating>(Parameters["trainfile"], Parameters["testfile"], new ItemRatingMap()); } else { throw new WrapRecException("Not enough information about dataset. Check help!"); } // step 2: recommender IModel recommender = GetRecommender(); Console.WriteLine("\nRecommender: {0}\n", recommender.GetType().Name); // step3: evaluation var ep = new EvaluationPipeline <ItemRating>(new EvalutationContext <ItemRating>(recommender, dataset)); ep.Evaluators.Add(new RMSE()); ep.Evaluators.Add(new MAE()); ep.Run(); }
static void Run(string trainingSet, string testSet) { // step 1: dataset var container = new MovieTweetingsDataContainer(); var reader = new MovieTweetingsReader(trainingSet, testSet); reader.LoadData(container); Console.WriteLine("Data container statistics:\n {0}", container.ToString()); var dataset = new ItemRatingDataset(container); var featureBuilder = new MovieTweetingLibSvmFeatureBuilder(container); // svm parameters var svmParameters = new SvmParameter { SvmType = SvmType.C_SVC, KernelType = KernelType.Linear, CacheSize = 128, C = 1, Eps = 1e-3, Shrinking = true, Probability = false }; // step 2: recommender var labelSelector = new Func <ItemRating, double>(ir => { var t = container.Tweets[ir]; return(((t.RetweetCount + t.FavoriteCount) > 0) ? 1.0 : 0.0); }); var recommender = new LibSvmClassifier(svmParameters, featureBuilder, labelSelector); // step3: evaluation var ep = new EvaluationPipeline <ItemRating>(new EvalutationContext <ItemRating>(recommender, dataset)); ep.Evaluators.Add(new WriteChallengeOutput(container, "test_output.dat")); ep.Run(); }
public void RunDemo() { // step 1: load dataset var container = new CrowdRecDataContainer(); var reader = new CrowdRecDataReader(_entitesFile, _relationsFile); reader.LoadData(container); var dataset = new ItemRatingDataset(container, 0.3f); // step 2: recommender var recommender = new MediaLiteRatingPredictor(new BiasedMatrixFactorization()); // step 3: evaluations var pipline = new EvaluationPipeline<ItemRating>(new EvalutationContext<ItemRating>(recommender, dataset)); pipline.Evaluators.Add(new RMSE()); pipline.Evaluators.Add(new MAE()); pipline.Run(); }
static void Run(string trainingSet, string testSet) { // step 1: dataset var container = new MovieTweetingsDataContainer(); var reader = new MovieTweetingsReader(trainingSet, testSet); reader.LoadData(container); Console.WriteLine("Data container statistics:\n {0}", container.ToString()); var dataset = new ItemRatingDataset(container); var featureBuilder = new MovieTweetingLibSvmFeatureBuilder(container); // svm parameters var svmParameters = new SvmParameter { SvmType = SvmType.C_SVC, KernelType = KernelType.Linear, CacheSize = 128, C = 1, Eps = 1e-3, Shrinking = true, Probability = false }; // step 2: recommender var labelSelector = new Func<ItemRating, double>(ir => { var t = container.Tweets[ir]; return ((t.RetweetCount + t.FavoriteCount) > 0) ? 1.0 : 0.0; }); var recommender = new LibSvmClassifier(svmParameters, featureBuilder, labelSelector); // step3: evaluation var ep = new EvaluationPipeline<ItemRating>(new EvalutationContext<ItemRating>(recommender, dataset)); ep.Evaluators.Add(new WriteChallengeOutput(container, "test_output.dat")); ep.Run(); }
public void TestCrossDomain() { // step 1: dataset var config = new CsvConfiguration() { Delimiter = ",", HasHeaderRecord = true }; var container = new CrossDomainDataContainer(); var domain1 = new Domain("domain1", true); var domain2 = new Domain("domain2"); var trainReader = new CsvReader(Paths.TestDomain1Train, config, domain1); var auxReader = new CsvReader(Paths.TestDomain2, config, domain2); var testReader = new CsvReader(Paths.TestDomain1Test, config, domain1, true); trainReader.LoadData(container); auxReader.LoadData(container); testReader.LoadData(container); var dataset = new ItemRatingDataset(container); var featureBuilder = new CrossDomainLibFmFeatureBuilder(domain1); // step 2: recommender var recommender = new LibFmTrainTester(featureBuilder: featureBuilder); // step3: evaluation var ep = new EvaluationPipeline <ItemRating>(new EvalutationContext <ItemRating>(recommender, dataset)); ep.Evaluators.Add(new RMSE()); ep.Evaluators.Add(new MAE()); ep.Run(); // featureBuilder.Mapper.OriginalIDs.ToList().ForEach(Console.WriteLine); // featureBuilder.Mapper.InternalIDs.ToList().ForEach(Console.WriteLine); }
public void RunDemo() { // step 1: load dataset var container = new CrowdRecDataContainer(); var reader = new CrowdRecDataReader(_entitesFile, _relationsFile); reader.LoadData(container); var dataset = new ItemRatingDataset(container, 0.3f); // step 2: recommender var recommender = new MediaLiteRatingPredictor(new BiasedMatrixFactorization()); // step 3: evaluations var pipline = new EvaluationPipeline <ItemRating>(new EvalutationContext <ItemRating>(recommender, dataset)); pipline.Evaluators.Add(new RMSE()); pipline.Evaluators.Add(new MAE()); pipline.Run(); }
public void TestAmazonDatasetSingleNewModel() { // step 1: dataset var config = new CsvConfiguration() { Delimiter = ",", HasHeaderRecord = true }; var trainContainer = new DataContainer(); var testContainer = new DataContainer(); var trainReader = new CsvReader(Paths.AmazonBooksTrain75, config); var testReader = new CsvReader(Paths.AmazonBooksTest25, config); trainReader.LoadData(trainContainer); testReader.LoadData(testContainer); var dataset = new ItemRatingDataset(trainContainer, testContainer); //var featureBuilder = new LibFmFeatureBuilder(); // step 2: recommender var recommender = new LibFmTrainTester(); // step3: evaluation var ep = new EvaluationPipeline <ItemRating>(new EvalutationContext <ItemRating>(recommender, dataset)); ep.Evaluators.Add(new RMSE()); ep.Evaluators.Add(new MAE()); ep.Run(); }
public void TestCrossDomain() { // step 1: dataset var config = new CsvConfiguration() { Delimiter = ",", HasHeaderRecord = true }; var container = new CrossDomainDataContainer(); var domain1 = new Domain("domain1", true); var domain2 = new Domain("domain2"); var trainReader = new CsvReader(Paths.TestDomain1Train, config, domain1); var auxReader = new CsvReader(Paths.TestDomain2, config, domain2); var testReader = new CsvReader(Paths.TestDomain1Test, config, domain1, true); trainReader.LoadData(container); auxReader.LoadData(container); testReader.LoadData(container); var dataset = new ItemRatingDataset(container); var featureBuilder = new CrossDomainLibFmFeatureBuilder(domain1); // step 2: recommender var recommender = new LibFmTrainTester(featureBuilder: featureBuilder); // step3: evaluation var ep = new EvaluationPipeline<ItemRating>(new EvalutationContext<ItemRating>(recommender, dataset)); ep.Evaluators.Add(new RMSE()); ep.Evaluators.Add(new MAE()); ep.Run(); // featureBuilder.Mapper.OriginalIDs.ToList().ForEach(Console.WriteLine); // featureBuilder.Mapper.InternalIDs.ToList().ForEach(Console.WriteLine); }
public void TestAmazonDatasetSingleNewModel() { // step 1: dataset var config = new CsvConfiguration() { Delimiter = ",", HasHeaderRecord = true }; var trainContainer = new DataContainer(); var testContainer = new DataContainer(); var trainReader = new CsvReader(Paths.AmazonBooksTrain75, config); var testReader = new CsvReader(Paths.AmazonBooksTest25, config); trainReader.LoadData(trainContainer); testReader.LoadData(testContainer); var dataset = new ItemRatingDataset(trainContainer, testContainer); //var featureBuilder = new LibFmFeatureBuilder(); // step 2: recommender var recommender = new LibFmTrainTester(); // step3: evaluation var ep = new EvaluationPipeline<ItemRating>(new EvalutationContext<ItemRating>(recommender, dataset)); ep.Evaluators.Add(new RMSE()); ep.Evaluators.Add(new MAE()); ep.Run(); }