public void ClassifyTest() { var classifier = new NaiveBayesClassifier(); var trainingData = new List <Tuple <string, IEnumerable <string> > > { new Tuple <string, IEnumerable <string> >("Food", new[] { "apple", "orange" }), new Tuple <string, IEnumerable <string> >("Food", new[] { "apple", "cake", "banana" }), new Tuple <string, IEnumerable <string> >("Animal", new[] { "cat", "dog" }), new Tuple <string, IEnumerable <string> >("Animal", new[] { "bird", "cat", "apple" }), }; classifier.Train(trainingData); var category = classifier.Classify(new[] { "dog" }); Assert.AreEqual("Animal", category); category = classifier.Classify(new[] { "apple", "banana" }); Assert.AreEqual("Food", category); }
public override void Train(ILabeledExampleCollection <LblT, SparseVector <double> > dataset) { var ds = (LabeledDataset <LblT, SparseVector <double> >)dataset; mModel.Train((LabeledDataset <LblT, BinaryVector>)ds.ConvertDataset(typeof(BinaryVector), false)); }