Machine learning 朴素贝叶斯-类标签1没有样本
我正在使用accord.net。我已经成功地实现了两个决策树算法ID3和C4.5,现在我正在尝试实现Naive Bays算法。虽然网站上有很多示例代码,但其中大部分似乎已经过时,或者存在各种问题 到目前为止,我在网站上找到的最佳示例代码如下: 但是,当我尝试针对我的数据运行该代码时,我得到: 没有类别标签1的示例。请确保这门课 标签是连续的,并且至少有一个用于 每个标签 从该文件的第228行开始: 当我打电话时 学习者。在我的代码中学习(输入、输出) 我已经遇到了accord在实现另外两个回归树时遇到的空bug,我的数据已经针对这个问题进行了清理 有没有雅阁网的专家知道是什么触发了这个错误 我的代码摘录:Machine learning 朴素贝叶斯-类标签1没有样本,machine-learning,naivebayes,accord.net,Machine Learning,Naivebayes,Accord.net,我正在使用accord.net。我已经成功地实现了两个决策树算法ID3和C4.5,现在我正在尝试实现Naive Bays算法。虽然网站上有很多示例代码,但其中大部分似乎已经过时,或者存在各种问题 到目前为止,我在网站上找到的最佳示例代码如下: 但是,当我尝试针对我的数据运行该代码时,我得到: 没有类别标签1的示例。请确保这门课 标签是连续的,并且至少有一个用于 每个标签 从该文件的第228行开始: 当我打电话时 学习者。在我的代码中学习(输入、输出) 我已经遇到了accord在实现另外两个回归
var codebook = new Codification(fulldata, AllAttributeNames);
/*
* Get list of all possible combinations
* Status software blows up if it encounters a value it has not seen before.
*/
var attributList = new List<IUnivariateFittableDistribution>();
foreach (var attr in DeciAttributeNames)
{
{
/*
* By default we'll use a standard static list of values for this column
*/
var cntLst = codebook[attr].NumberOfSymbols;
// no decisions can be made off of the variable if it is a constant value
if (cntLst > 1)
{
KeptAttributeNames.Add(attr);
attributList.Add(new GeneralDiscreteDistribution(cntLst));
}
}
}
var data = fulldata.Copy(); // this is a datatable
/*
* Translate our training data into integer symbols using our codebook
*/
DataTable symbols = codebook.Apply(data, AllAttributeNames);
double[][] inputs = symbols.ToJagged<double>(KeptAttributeNames.ToArray());
int[] outputs = symbols.ToArray<int>(OutAttributeName);
progBar.PerformStep();
/*
* Create a new instance of the learning algorithm
* and build the algorithm
*/
var learner = new NaiveBayesLearning<IUnivariateFittableDistribution>()
{
// Tell the learner how to initialize the distributions
Distribution = (classIndex, variableIndex) => attributList[variableIndex]
};
var alg = learner.Learn(inputs, outputs);
var codebook=新编码(fulldata,AllAttributeNames);
/*
*获取所有可能组合的列表
*状态软件遇到以前从未见过的值时会崩溃。
*/
var attributelist=新列表();
foreach(DeciAttributeName中的var attr)
{
{
/*
*默认情况下,我们将为此列使用标准静态值列表
*/
var cntLst=codebook[attr].NumberOfSymbols;
//如果变量是常数值,则无法对其进行决策
如果(cntLst>1)
{
KeptAttributeNames.Add(attr);
Add(新的GeneralDiscretedDistribution(cntLst));
}
}
}
var data=fulldata.Copy();//这是一个数据表
/*
*使用码本将训练数据转换为整数符号
*/
DataTable symbols=codebook.Apply(数据,所有属性名称);
double[][]输入=symbols.ToJagged(KeptAttributeNames.ToArray());
int[]输出=symbols.ToArray(OutAttributeName);
progBar.PerformStep();
/*
*创建学习算法的新实例
*并建立了算法
*/
var learner=new NaiveBayesLearning()
{
//告诉学员如何初始化分发
分布=(classIndex,variableIndex)=>AttributeList[variableIndex]
};
var alg=学习者学习(输入、输出);
编辑:在进一步的实验之后,似乎只有在处理一定数量的行时才会发生此错误。如果我处理了60行或少于60行,那么我很好;如果我处理了500行或多于500行,那么我很好。但在这个范围内,我抛出了这个错误。根据我选择的数据量,错误消息中的索引号可能会改变,我看到它的范围是0到2
所有数据都来自同一个sql server数据源,我唯一要调整的是查询的Select Top部分。当您定义了一个没有任何样本数据的标签时,您将在多类场景中收到此错误。使用一个小数据集,您的随机抽样可能会偶然排除具有给定标签的所有观察。今天早上,我生成了一条稍微好一点的错误消息,这使我解决了这个问题。很高兴知道,此错误也是训练数据与为其配置的标签之间的对比的结果。