Beispiel #1
0
        public ProcessResult GetProcessResult(PipelineContext context)
        {
            var pr = new ProcessResult();

            pr["MediaLite_RMSE"] = context.GetAsString("MediaLite_RMSE");
            pr["MediaLite_MAE"]  = context.GetAsString("MediaLite_MAE");

            return(pr);
        }
Beispiel #2
0
        public ProcessResult GetProcessResult(PipelineContext context)
        {
            var pr = new ProcessResult();

            pr["LibFmTrainRMSE"] = context.GetAsString("LibFmTrainRMSE");
            pr["LibFmTestRMSE"]  = context.GetAsString("LibFmTestRMSE");
            pr["LibFmTestMAE"]   = context.GetAsString("LibFmTestMAE");

            return(pr);
        }
Beispiel #3
0
        public ProcessConfiguration GetConfiguration(PipelineContext context)
        {
            var pc = new ProcessConfiguration();

            pc["Recommender"] = _recommender.GetType().Name;
            pc["TrainFile"]   = context.GetAsString("TrainFile");
            pc["TestFile"]    = context.GetAsString("TestFile");

            return(pc);
        }
        public ProcessResult GetProcessResult(PipelineContext context)
        {
            var pr = new ProcessResult();

            pr["TrainFile"] = context.GetAsString("TrainFile");
            pr["TestFile"]  = context.GetAsString("TestFile");
            pr["TargetDomainTrainCount"] = context.GetAsString("TargetDomainTrainCount");
            pr["TargetDomainTest"]       = context.GetAsString("TargetDomainTest");
            pr["AuxDomainsCount"]        = context.GetAsString("AuxDomainsCount");

            return(pr);
        }
Beispiel #5
0
        public ProcessConfiguration GetConfiguration(PipelineContext context)
        {
            var pc = new ProcessConfiguration();

            pc["LearningAlgorithm"] = LearningAlgorithm.ToString();
            pc["Iterations"]        = Iterations.ToString();
            pc["Dimensions"]        = Dimensions;
            pc["LearningRate"]      = LearningRate.ToString();
            pc["TrainFile"]         = context.GetAsString("TrainFile");
            pc["TestFile"]          = context.GetAsString("TestFile");
            pc["AdditionalArgs"]    = _additionalArgs;

            return(pc);
        }
        public ProcessResult GetProcessResult(PipelineContext context)
        {
            var pr = new ProcessResult();

            pr["MovieLensFile"] = context.GetAsString("MovieLensFile");

            return(pr);
        }
Beispiel #7
0
        public void Process(PipelineContext context)
        {
            var    products       = context["AmazonProducts"] as IList <AmazonProduct>;
            string amazonDataFile = context.GetAsString("AmazonDataFile");

            var outputFile = string.Format("{0}\\{1}4.libfm", amazonDataFile.GetDirectoryPath(), amazonDataFile.GetFileName());
            var featDic    = new Dictionary <string, int>();

            ConvertToLibFmFile(products, outputFile, featDic);

            context["LibFmFile"] = outputFile;
        }
        public override void Process(PipelineContext context)
        {
            string movieLensTrain = context.GetAsString("TrainFile");
            string movieLensTest  = context.GetAsString("TestFile");

            string libFmTrain = movieLensTrain.GetDirectoryPath() + "\\" + movieLensTrain.GetFileName() + ".libfm";
            string libFmTest  = movieLensTest.GetDirectoryPath() + "\\" + movieLensTest.GetFileName() + ".libfm";

            if (!File.Exists(libFmTrain) || !UseCach)
            {
                var featDic = new Dictionary <string, int>();

                ConvertToLibFmFile(movieLensTrain, libFmTrain, featDic);
                ConvertToLibFmFile(movieLensTest, libFmTest, featDic);
            }
            else
            {
                Console.WriteLine("==> loading cached data");
            }

            context["TrainFile"] = libFmTrain;
            context["TestFile"]  = libFmTest;
        }
Beispiel #9
0
        public void Process(PipelineContext context)
        {
            string movieLensTrain = context.GetAsString("TrainFile");
            string movieLensTest  = context.GetAsString("TestFile");

            var usersMap = new Mapping();
            var itemsMap = new Mapping();

            IRatings trainSet = ReadData(movieLensTrain, usersMap, itemsMap);
            IRatings testSet  = ReadData(movieLensTest, usersMap, itemsMap);

            var recom = _recommender as IRatingPredictor;

            recom.Ratings = trainSet;

            Console.WriteLine("Training...");
            recom.Train();

            Console.WriteLine("Testing...");
            var results = recom.Evaluate(testSet);

            context["MediaLite_RMSE"] = results["RMSE"];
            context["MediaLite_MAE"]  = results["MAE"];
        }
        public override void Process(PipelineContext context)
        {
            string movieLensFile = context.GetAsString("MovieLensFile");

            var ratings = File.ReadAllLines(movieLensFile).Select(l => new ItemRating(l))
                          .GroupBy(r => r.UserId)
                          .Where(g => g.Count() >= _minNumRatings)
                          .SelectMany(g => g.Select(r => r.ToString()));

            string outputFile = string.Format("{0}\\{1}-filter{2}.ml",
                                              movieLensFile.GetDirectoryPath(), movieLensFile.GetFileName(), _minNumRatings);

            File.WriteAllLines(outputFile, ratings.Shuffle());

            context["MovieLensFile"] = outputFile;
        }
Beispiel #11
0
        public override void Process(PipelineContext context)
        {
            string inputFile = context.GetAsString(ContextName);

            string trainFile = String.Format("{0}\\{1}-train{2}.{3}",
                                             inputFile.GetDirectoryPath(), inputFile.GetFileName(), TrainRatio.ToString(), inputFile.GetFileExtension());
            string testFile = String.Format("{0}\\{1}-test{2}.{3}",
                                            inputFile.GetDirectoryPath(), inputFile.GetFileName(), TrainRatio.ToString(), inputFile.GetFileExtension());

            if (!File.Exists(trainFile) || !UseCach)
            {
                Spilit(inputFile, trainFile, testFile, TrainRatio);
            }
            else
            {
                Console.WriteLine("==> loading cached data");
            }

            context["TrainFile"] = trainFile;
            context["TestFile"]  = testFile;
        }
Beispiel #12
0
        public void Process(PipelineContext context)
        {
            string libFmTrain = context.GetAsString("TrainFile");
            string libFmTest  = context.GetAsString("TestFile");

            _testOutput = string.Format("{0}\\{1}.out", libFmTest.GetDirectoryPath(), libFmTest.GetFileName());

            var libFm = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = _libFmPath,
                    Arguments              = BuildArguments(libFmTrain, libFmTest),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            string libFMTrainRMSE = "", libFMTestRMSE = "";

            double prevRMSE = double.MaxValue;
            int    iter     = 0;

            libFm.OutputDataReceived += (p, dataLine) =>
            {
                var data = dataLine.Data;

                if (data != null && (data.StartsWith("Loading") || data.StartsWith("#")))
                {
                    Console.WriteLine(dataLine.Data);

                    // Store the results of this apprach in pipeline context
                    if (data.StartsWith("#Iter"))
                    {
                        libFMTrainRMSE = data.Substring(data.IndexOf("Train") + 6, 6);
                        libFMTestRMSE  = data.Substring(data.IndexOf("Test") + 5);

                        // Stop libFm if there was no improvement in RMSE
                        // Note: stopping LibFm will prevent the output file to be created
                        if (StopWhenNoImprovment)
                        {
                            double current = double.Parse(libFMTestRMSE);

                            if (current > prevRMSE)
                            {
                                libFm.Kill();
                            }
                            else
                            {
                                prevRMSE = current;
                            }
                        }
                        iter++;
                    }
                }
            };

            libFm.Start();
            libFm.BeginOutputReadLine();
            libFm.WaitForExit();

            context["LibFmTrainRMSE"] = libFMTrainRMSE;
            context["LibFmTestRMSE"]  = libFMTestRMSE;

            // If this file exists it means the process finished normally and the MAE can be calculated
            if (File.Exists(_testOutput))
            {
                context["LibFmTestMAE"] = CalculateMAE(libFmTest);
            }
            else
            {
                context["LibFmTestMAE"] = "LibFM exited at iter " + iter;
            }
        }