Naveen
Naveen

Reputation: 791

how to run mahout kmeans algorithm in local mode

Is it possible to run a mahout k mean java program on local, so that it will read the data from local and save it back to local file system instead of hdfs. All examles on internet are working on hdfs.

https://github.com/tdunning/MiA/blob/master/src/main/java/mia/clustering/ch07/SimpleKMeansClustering.java

Upvotes: 0

Views: 362

Answers (1)

Venkat Rangan
Venkat Rangan

Reputation: 385

Yes, it is possible - checkout SequenceFileWriter. See the following code example, which writes clustered data points to a file. Here is a blog post that describes this in great detail:

public static void writePointsToFile(List<Vector> points,
                                     String fileName,
                                     FileSystem fs,
                                     Configuration conf) throws IOException {
    Path path = new Path(fileName);
    SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,
            path, LongWritable.class, VectorWritable.class);
    long recNum = 0;
    VectorWritable vec = new VectorWritable();
    for (Vector point : points) {
        vec.set(point);
        writer.append(new LongWritable(recNum++), vec);
    }
    writer.close();
}

Upvotes: 1

Related Questions