我有一个关于Mahout的问题:当我用补充模型和标准模型方法测试训练有素的朴素贝叶斯模型时,为什么我会在混淆矩阵中得到相同的测试结果(相同的模型测试精度--80%)?
以下是我使用的步骤:
-
向矢量转换:
# mahout seq2sparse --input /user/root/data-seq/chunk-0 --output /user/root/vectors -ow -wt tfidf -md 2 -x 95 -n 2 -nr 2
-
分裂训练和测试向量:
# mahout split --input data-vectors/tfidf-vectors --trainingOutput training-vectors --testOutput test-vectors --randomSelectionPct 30 --overwrite --sequenceFiles -xm sequential
-
学习模型:a)
ComplementaryNaiveBayesClassifier: # mahout trainnb -i training-vectors -el -li labelindex -o model -ow -c
b)StandardNaiveBayesClassifier: # mahout trainnb -i training-vectors -el -li labelindex -o model -ow
-
测试模型:a)
ComplementaryNaiveBayesClassifier: # mahout testnb -i training-vectors -m model -l labelindex -ow -o tweets-testing -c
b)StandardNaiveBayesClassifier: # mahout testnb -i training-vectors -m model -l labelindex -ow -o tweets-testing
也许是因为标准朴素贝叶斯不使用权重归一化但我在第一步中通过设置参数使用它: -n 2
?如果是真的,意味着如果我想比较这些算法的性能,我不应该在创建向量时使用此参数?
1 回答
您为
mahout seq2sparse
引用的-n 2选项实际上是指定用于长度归一化的L_p规范[1] . 因此mahout seq2sparse ... -n 2
使用TF-IDF向量的L_2长度归一化 . 或者,您可以使用-lnorm
进行对数标准化 . 这是用于补充和标准朴素贝叶斯[2]之前的预处理步骤的一部分 .权重标准化与长度标准化不同,不在Mahout 0.7中使用 .
在即将发布的1.0版本中使用权重标准化,以便获得标准和补充朴素贝叶斯的最佳比较,您应该检查并构建最新主干的副本:http://mahout.apache.org/developers/buildingmahout.html .
如果升级到最新的主干,您应该会看到Standard和Complement Naive Bayes之间存在显着差异 .
[1] mahout.apache.org/users/basics/creating-vectors-from-text.html
[2] http://mahout.apache.org/users/classification/bayesian.html