當前位置: 首頁>>代碼示例>>C#>>正文


C# Algorithm.Classify方法代碼示例

本文整理匯總了C#中Algorithm.Classify方法的典型用法代碼示例。如果您正苦於以下問題:C# Algorithm.Classify方法的具體用法?C# Algorithm.Classify怎麽用?C# Algorithm.Classify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Algorithm的用法示例。


在下文中一共展示了Algorithm.Classify方法的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.Classify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。