4

我的环境:mahout:0.7 hadoop:1.0.3

我所做的:安装了 mahout,并测试了朴素的贝叶斯示例 - 20newsgroup,它运行良好。

我想要实现的:有trainnbtestnb工作,但是,在实际应用中,我们需要这样的接口:

输入:[要分类的文本] [要使用的模型] 输出:类标签列表(按概率排序)

我已经尝试过:首先我尝试作为testnb工作,但我不知道如何将文本转换为由 StandardNaiveBayesClassifier 或 ComplementaryNaiveBayesClassifier 处理的“VectorWritable”对象。

代码:

SequenceFile.Writer writer = new SequenceFile.Writer
 (fs, getConf(), getOutputPath(), Text.class, VectorWritable.class);
Path inputFile = new Path(getOption("if"));
Reader reader = new Reader(fs, getInputPath(), getConf());
Text key = new Text();
  VectorWritable vw = new VectorWritable();
  while (reader.next(key, vw)) {
    writer.append(
            new Text(SLASH.split(key.toString())[1]),
            new VectorWritable(classifier.classifyFull(vw.get()))
            );
  }

任何帮助将不胜感激!

我想我明白了,在“mahout in action”中,第 16 章有一些示例代码。

4

1 回答 1

2

你检查过这篇文章吗

http://chimpler.wordpress.com/2013/03/13/using-the-mahout-naive-bayes-classifier-to-automatically-classify-twitter-messages/

我完成了教程,一切正常

于 2014-01-27T10:12:43.160 回答