c# - 示例 Accord.NET 朴素贝叶斯

标签 c# .net machine-learning naivebayes accord.net

我是 accord.net 的新手,我正在尝试逐步应用此 page 中的以下代码转换为 Visual Studio C#

的简单应用程序

“标准分类问题”部分的代码已毫无问题地应用,但是当我尝试在运行时应用“朴素贝叶斯”部分的代码时,我遇到了该描述的异常

mscorlib.dll 中发生 System.AggregateException 类型的未处理异常 不再赘述。

这发生在以下命令中

var nb = learner.Learn(输入,输出)

我的代码如下

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();

我的程序的堆栈跟踪

enter image description here

最佳答案

从您在帖子中指出的同一页面下载的examples.xls似乎包含错误/不兼容/过时的数据。在 G 列中,使用 Accord v3.4.2- 将所有 -1 替换为 0(第 2 至 51 行)即可解决问题阿尔法

enter image description here

enter image description here

enter image description here

关于c# - 示例 Accord.NET 朴素贝叶斯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42299201/

相关文章:

c# - quartz 、Unity 和 .NET

python - 用于分布式训练的 Tensorflow 输入管道

machine-learning - 新闻文章的聚类

pandas - 如何将 FastAPI 中的 Pydantic 模型转换为 Pandas DataFrame?

c# - 使 C# 保存 16 位位图而不进行位域压缩

c# - .NET/甲骨文 : How to execute a script with DDL statements programmatically

c# - 拒绝对 DataRow 中单个 DataColumn 的更改

c# - 如何在 C# 中将结构转换为字节数组?

c# - 一个单一的通用解决方案?

c# - 使用@Url.Action 生成 URL