我有一个关于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
使用了它?如果这是真的,是否意味着如果我想比较这些算法的性能,我不应该在创建向量时使用这个参数?
回答:
您提到的mahout seq2sparse
的-n 2选项实际上是指定用于长度归一化的L_p范数[1]。所以mahout seq2sparse ... -n 2
使用L_2长度归一化TF-IDF向量。或者,您可以使用-lnorm
进行对数归一化。这是互补和标准朴素贝叶斯使用的预处理步骤的一部分[2]。
权重归一化与长度归一化不同,在Mahout 0.7中未使用。
权重归一化将在即将发布的1.0版本中使用,因此为了获得标准和互补朴素贝叶斯的最佳比较,您应该检出并构建最新主干的副本:http://mahout.apache.org/developers/buildingmahout.html。
如果您升级到最新主干,您应该会看到标准和互补朴素贝叶斯之间的显著差异。
[1] mahout.apache.org/users/basics/creating-vectors-from-text.html
[2] http://mahout.apache.org/users/classification/bayesian.html