Example usage for org.apache.mahout.clustering.classify WeightedPropertyVectorWritable WeightedPropertyVectorWritable

List of usage examples for org.apache.mahout.clustering.classify WeightedPropertyVectorWritable WeightedPropertyVectorWritable

Introduction

In this page you can find the example usage for org.apache.mahout.clustering.classify WeightedPropertyVectorWritable WeightedPropertyVectorWritable.

Prototype

public WeightedPropertyVectorWritable() 

Source Link

Usage

From source file:hk.newsRecommender.MatrixAndCluster.java

License:Open Source License

public static void clusterOutput(Configuration conf, Path path) {
    try {//from w w w .ja  v  a 2 s. co  m
        BufferedWriter bw;
        FileSystem fs = FileSystem.get(conf);

        SequenceFile.Reader reader = null;
        reader = new SequenceFile.Reader(fs, path, conf);

        // ?uidOfgrp.txt?? uid \t groupID
        bw = new BufferedWriter(new FileWriter(new File("C:\\Users\\Hk\\Desktop\\ClusterPointsInfo.txt")));
        HashMap<String, Integer> clusterIds;
        clusterIds = new HashMap<String, Integer>(120);
        IntWritable key = new IntWritable();
        WeightedPropertyVectorWritable value = new WeightedPropertyVectorWritable();
        //         WeightedVectorWritable value = new WeightedVectorWritable();
        while (reader.next(key, value)) {
            NamedVector vector = (NamedVector) value.getVector();
            // VectorName
            String vectorName = vector.getName();
            System.out.println(vectorName + "\t" + key.toString());
            bw.write(vectorName + "\t" + key.toString() + "\n");
            // ?group?
            if (clusterIds.containsKey(key.toString())) {
                clusterIds.put(key.toString(), clusterIds.get(key.toString()) + 1);
            } else
                clusterIds.put(key.toString(), 1);
        }
        bw.flush();
        reader.close();
        // ?group?grpSize
        bw = new BufferedWriter(new FileWriter(new File("C:\\Users\\Hk\\Desktop\\ClusterPointsSize.txt")));
        Set<String> keys = clusterIds.keySet();
        for (String k : keys) {
            System.out.println(k + " " + clusterIds.get(k));
            bw.write(k + " " + clusterIds.get(k) + "\n");
        }
        bw.flush();
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:hk.newsRecommender.MatrixAndCluster.java

License:Open Source License

public static void clusterOutput2(Configuration conf, Path path) {
    try {//from w  ww  . j a  va2 s.  c o  m
        FileSystem fs = FileSystem.get(conf);
        SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf);
        IntWritable key = new IntWritable();
        WeightedPropertyVectorWritable value = new WeightedPropertyVectorWritable();
        while (reader.next(key, value)) {
            System.out.println(value.toString() + " belongs to cluster " + key.toString());
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:sigis.kmeansmultiplek.AnotherKmeans.java

private void readAndPrintOutputValues(final Configuration configuration) throws IOException {
    final Path input = new Path(OUTPUT_PATH + "/" + Cluster.CLUSTERED_POINTS_DIR + "/part-m-00000");
    //final Path input = new Path(OUTPUT_PATH + "/" + Cluster.FINAL_ITERATION_SUFFIX + "/part-r-00000");
    System.out.println(Cluster.FINAL_ITERATION_SUFFIX);
    System.out.println(Cluster.CLUSTERED_POINTS_DIR);

    final SequenceFile.Reader reader = new SequenceFile.Reader(configuration, SequenceFile.Reader.file(input));

    final IntWritable key = new IntWritable();
    final WeightedPropertyVectorWritable value = new WeightedPropertyVectorWritable();

    while (reader.next(key, value)) {
        LOG.info("{} belongs to cluster {}", value.toString(), key.toString());
        System.out.println(value.toString().substring(18, 28));
        LOG.info("belongs to cluster {}", key.toString());

    }//  www .  j a v  a  2 s  . com
    reader.close();
}