示例#1
0
        public void TestAuxDataSize()
        {
            // step 1: dataset
            var config = new CsvConfiguration()
            {
                Delimiter = ",",
                HasHeaderRecord = true
            };

            var container = new CrossDomainDataContainer();

            var bookDomain = new Domain("book", true);
            var musicDomain = new Domain("music");
            var dvdDomain = new Domain("dvd");
            var videoDomain = new Domain("video");

            var bookReader = new CsvReader("books_selected4.csv", config, bookDomain);
            //var trainReader = new CsvReader("books_selected1_train.csv", config, bookDomain);
            //var testReader = new CsvReader("books_selected1_test.csv", config, bookDomain, true);
            var musicReader = new CsvReader(Paths.AmazonAllMusicRatings, config, musicDomain);
            var dvdReader = new CsvReader(Paths.AmazonAllDvdRatings, config, dvdDomain);
            var videoReader = new CsvReader(Paths.AmazonAllVideoRatings, config, videoDomain);

            bookReader.LoadData(container);
            //trainReader.LoadData(container);
            //testReader.LoadData(container);
            musicReader.LoadData(container);
            //dvdReader.LoadData(container);
            //videoReader.LoadData(container);

            container.PrintStatistics();

            var splitter = new CrossDomainSimpleSplitter(container, 0.25f);
            //splitter.SaveSplitsAsCsv("books_selected1_train.csv", "books_selected1_test.csv");

            var rmse = new List<string>();
            var mae = new List<string>();
            var durations = new List<string>();

            for (int i = 0; i < 10; i++)
            {
                var startTime = DateTime.Now;

                musicDomain.ActivateData(0.1f);

                // step 2: recommender
                LibFmTrainTester recommender;
                CrossDomainLibFmFeatureBuilder featureBuilder = null;

                featureBuilder = new CrossDomainLibFmFeatureBuilder(bookDomain, 10);
                recommender = new LibFmTrainTester(experimentId: i.ToString(), featureBuilder: featureBuilder);

                // step3: evaluation
                var ctx = new EvalutationContext<ItemRating>(recommender, splitter);
                var ep = new EvaluationPipeline<ItemRating>(ctx);
                ep.Evaluators.Add(new RMSE());
                ep.Evaluators.Add(new MAE());
                ep.Run();

                rmse.Add(recommender.RMSE.ToString());
                mae.Add(ctx["MAE"].ToString());

                var duration = DateTime.Now.Subtract(startTime);
                durations.Add(((int)duration.TotalMilliseconds).ToString());
            }

            Console.WriteLine("NumAuxRatings\tRMSE\tMAE\tDuration");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", i, rmse[i], mae[i], durations[i]);
            }
        }
示例#2
0
        public void TestAuxDataSize()
        {
            // step 1: dataset
            var config = new CsvConfiguration()
            {
                Delimiter       = ",",
                HasHeaderRecord = true
            };

            var container = new CrossDomainDataContainer();

            var bookDomain  = new Domain("book", true);
            var musicDomain = new Domain("music");
            var dvdDomain   = new Domain("dvd");
            var videoDomain = new Domain("video");

            var bookReader = new CsvReader("books_selected4.csv", config, bookDomain);
            //var trainReader = new CsvReader("books_selected1_train.csv", config, bookDomain);
            //var testReader = new CsvReader("books_selected1_test.csv", config, bookDomain, true);
            var musicReader = new CsvReader(Paths.AmazonAllMusicRatings, config, musicDomain);
            var dvdReader   = new CsvReader(Paths.AmazonAllDvdRatings, config, dvdDomain);
            var videoReader = new CsvReader(Paths.AmazonAllVideoRatings, config, videoDomain);

            bookReader.LoadData(container);
            //trainReader.LoadData(container);
            //testReader.LoadData(container);
            musicReader.LoadData(container);
            //dvdReader.LoadData(container);
            //videoReader.LoadData(container);

            container.PrintStatistics();

            var splitter = new CrossDomainSimpleSplitter(container, 0.25f);
            //splitter.SaveSplitsAsCsv("books_selected1_train.csv", "books_selected1_test.csv");


            var rmse      = new List <string>();
            var mae       = new List <string>();
            var durations = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                var startTime = DateTime.Now;

                musicDomain.ActivateData(0.1f);

                // step 2: recommender
                LibFmTrainTester recommender;
                CrossDomainLibFmFeatureBuilder featureBuilder = null;

                featureBuilder = new CrossDomainLibFmFeatureBuilder(bookDomain, 10);
                recommender    = new LibFmTrainTester(experimentId: i.ToString(), featureBuilder: featureBuilder);


                // step3: evaluation
                var ctx = new EvalutationContext <ItemRating>(recommender, splitter);
                var ep  = new EvaluationPipeline <ItemRating>(ctx);
                ep.Evaluators.Add(new RMSE());
                ep.Evaluators.Add(new MAE());
                ep.Run();

                rmse.Add(recommender.RMSE.ToString());
                mae.Add(ctx["MAE"].ToString());

                var duration = DateTime.Now.Subtract(startTime);
                durations.Add(((int)duration.TotalMilliseconds).ToString());
            }

            Console.WriteLine("NumAuxRatings\tRMSE\tMAE\tDuration");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", i, rmse[i], mae[i], durations[i]);
            }
        }