5

label と tweets を含むテキスト ファイルがあります。

    positive,I love this car
    negative,I hate this book
    positive,Good product.

各行をベクター値に変換する必要がありますseq2sparse。コマンドを使用すると、ドキュメント全体がベクターに変換されますが、各行をドキュメント全体ではなくベクターとして変換する必要があります。ex : key : 正の値 : vectorvalue(tweet) mahout でこれを実現するにはどうすればよいでしょうか?


/* これが私がやったことです */

    StringTokenizer str= new StringTokenizer(line,",");
            String label=str.nextToken();
            while (str.hasMoreTokens())
            {
            tweetline =str.nextToken();
            System.out.println("Tweetline"+tweetline);
            StringTokenizer words = new StringTokenizer(tweetline," ");
            while(words.hasMoreTokens()){
            featureList.add(words.nextToken());}
            }
            Vector unclassifiedInstanceVector = new RandomAccessSparseVector(tweetline.split(" ").length);
 FeatureVectorEncoder vectorEncoder = new AdaptiveWordValueEncoder(label);
            vectorEncoder.setProbes(1);
            System.out.println("Feature List: "+featureList);
            for (Object feature: featureList) {
                vectorEncoder.addToVector((String) feature, unclassifiedInstanceVector);
            }
            context.write(new Text("/"+label), new VectorWritable(unclassifiedInstanceVector));

前もって感謝します

4

1 に答える 1

0

SequenceFile.Writer を使用して app hdfs パスに書き込むことができます

           FS = FileSystem.get(HBaseConfiguration.create());
           String newPath =   "/foo/mahouttest/part-r-00000";
           Path newPathFile = new Path(newPath);
           Text key = new Text();
           VectorWritable value = new VectorWritable();
           SequenceFile.Writer writer = SequenceFile.createWriter(FS, conf, newPathFile,
                key.getClass(), value.getClass());
                 .....
           key.set("c/"+label);
           value.set(unclassifiedInstanceVector );
           writer.append(key,value);
于 2013-03-22T08:23:16.067 に答える