当前位置: 首页>>代码示例>>C#>>正文


C# Algorithm.LearnNaiveBayesText方法代码示例

本文整理汇总了C#中Algorithm.LearnNaiveBayesText方法的典型用法代码示例。如果您正苦于以下问题:C# Algorithm.LearnNaiveBayesText方法的具体用法?C# Algorithm.LearnNaiveBayesText怎么用?C# Algorithm.LearnNaiveBayesText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Algorithm的用法示例。


在下文中一共展示了Algorithm.LearnNaiveBayesText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            if(args.Length != 2)
            {
                Console.WriteLine("Please use 2 arguments: splits/train# splits/test#");
                return;
            }
            string train = args[0];
            string test = args[1];

            string dir = Path.GetDirectoryName(Path.GetDirectoryName(train));
            string dataPath = Path.Combine(dir, "data");

            //DateTime start = DateTime.Now;

            // First, pull in all of the training files and store it in memory
            string[] files = File.ReadAllLines(train);

            Dictionary<string, string> examples = new Dictionary<string, string>(files.Length);
            foreach (string file in files)
                examples.Add(file, File.ReadAllText(Path.Combine(dataPath, file)));

            // Next, grab all of the test files and reall it all
            files = File.ReadAllLines(test);
            Dictionary<string, string> tests = new Dictionary<string, string>(files.Length);
            foreach (string file in files)
                tests.Add(file, File.ReadAllText(Path.Combine(dataPath, file)));

            Algorithm algo = new Algorithm();

            /*
             * Train the naive bayes algorithm to place weights on words
             * and classify these words for various labels based on
             * the training data.
             */
            algo.LearnNaiveBayesText(examples, LABELS);

            /*
             * Classify the test data based on the trained algorithm.
             */
            algo.Classify(tests, LABELS);

            //Console.WriteLine("This took: {0:s}", (DateTime.Now - start));

            // Output the results (can be pipe-directed to a file)
            foreach (KeyValuePair<string, string> entry in algo.classification)
                Console.WriteLine(entry.Key + " " + entry.Value);

            //Test.TestPath();
            //Test.TestSet();
            //Test.TestRegex();
            //Test.TestDictionarySort();

            //Console.WriteLine("Done, press enter to exit.");
            //Console.ReadLine();
        }
开发者ID:sonuk,项目名称:Naive-Bayes-Classifier,代码行数:56,代码来源:Program.cs


注:本文中的Algorithm.LearnNaiveBayesText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。