Search code examples
c#.netmachine-learningnaivebayesaccord.net

Sample Accord.NET Naive-Bayes


I am new in accord.net and i am trying to apply step by step the following code from this page into a simple application of Visual Studio C#

The code of the section "Standard classification problems" has been applied with no problem but when i try to apply the code from section "Naive Bayes" during run-time i got an exception with that desciption

unhandled exception of type System.AggregateException occurred in mscorlib.dll With no further desciption.

This happens in the following command

var nb = learner.Learn(inputs, outputs)

My code is the following

DataTable table = new celReader("examples.xls").GetWorksheet("Classification - Yin Yang");
 // Convert the DataTable to input and output vectors
 double[][] inputs = table.ToArray<double>("X", "Y");
 int[] outputs = table.Columns["G"].ToArray<int>();

 // Plot the data
 ScatterplotBox.Show("Yin-Yang", inputs, outputs).Hold();

 var learner = new NaiveBayesLearning<NormalDistribution>();
 // Estimate the Naive Bayes
 var nb = learner.Learn(inputs, outputs); // this is where exception is thrown

 // Classify the samples using the model
 int[] answers = nb.Decide(inputs);

 // Plot the results
 ScatterplotBox.Show("Expected results", inputs, outputs);
 ScatterplotBox.Show("Naive Bayes results", inputs, answers).Hold();

The stacktrace of my program

enter image description here


Solution

  • The examples.xls downloaded from the same page you indicated in your post seems to have bad/incompatible/outdated data. In column G, replacing all -1 with 0 (rows 2 to 51) does the trick, using Accord v3.4.2-alpha.

    enter image description here

    enter image description here

    enter image description here