machine-learning - 朴素贝叶斯 - 没有类标签 0 的样本
问题描述
不久前我问了一个关于 Accord.net 朴素贝叶斯算法抛出错误的问题。事实证明,这是因为我使用了离散值输入列,但没有为我为该列列出的所有值提供足够的训练数据。
现在我得到了完全相同的错误,只是这一次只有当我对输出列使用连续值时才会触发它。特别是整数数据类型的输出列。因为它是一个整数,所以 Codification 类没有翻译它,所以值直接传递给朴素贝叶斯算法,而算法显然无法处理这个问题。
如果我手动将列数据类型更改为字符串并通过 Codification 类将其发送以进行编码,然后通过它正常工作的算法发送结果。
这个算法不能将连续数据类型作为输出处理有什么特别的原因吗?是否需要启用某些设置才能使其正常工作?
一些示例代码:
DataTable symbols = TrainingCodebook.Apply(DataTraining, AllAttributeNames);
double[][] inputs = symbols.ToJagged<double>(KeptAttributeNames.ToArray());
// *** The line that is breaking ***
int[] outputs = symbols.ToArray<int>(outputCol);
// *** The replacement test code that does work ***
// DataStringTraining is the same as DataTraining, but all values are strings
//Codification codeee = new Codification(DataStringTraining, outputCol);
//var sym = codeee.Apply(DataStringTraining, outputCol);
//int[] outputs = sym.ToArray<int>(outputCol);
/*
* 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],
};
NaiveBayes<IUnivariateFittableDistribution> alg = null;
try
{
ProgPerformStep("Computing and training algorithm");
alg = learner.Learn(inputs, outputs);
}
catch (Exception ex)
{
ProgPerformStep($"ERROR: Naive Bayes: {ex.Message}", ex);
return;
}
解决方案
我对此没有很好的答案,但是我相信正在发生的是我正在使用的算法在accord.net 网站上列为分类算法。
根据这里的一些阅读,我认为分类算法无法处理连续的输出值。
我可能需要切换到使用回归算法来获得该特定功能。
鉴于此,该算法的解决方案是手动编码输出列,或先将其转换为字符串,以便编码库为我完成这项工作。
推荐阅读
- java - 通过 POST /login API 实现 Spring Security 登录
- julia - 绘制函数的梯度逼近
- reactjs - React useNavigation 说无法对未安装的组件执行反应状态更新
- loops - 如何编写一个 vbscript 继续检查应用程序是否未运行并停止检查应用程序是否正在运行
- python-3.x - 为所有用户更改 python 和 python3 的默认版本
- excel - 从另一个具有不同日期的工作簿调用宏
- haskell - 如何从 int 列表和 Haskell 中的字符串列表创建字符串列表
- visual-studio - WPF - 保持圆角边框
- python - 如何在熊猫列中保存 str.contains() 的总和?
- python - 难以理解的输入行为