本文整理匯總了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();
}