mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksander Sadecki <>
Subject How to get Radius and Centers after KMeans algo
Date Tue, 24 Jun 2014 12:21:04 GMT

I would like to get info about RADIUS and CENTERS for each my cluster. Could you tell me how
I can do it?

I have got this piece of code and I would like to do it in the WHILE loop in the end.

Thank you in advance

	public static Map<String, ClusterPack> calculate(int numbOfClusters,
			String filename, List<String> headers) throws IOException,
			InterruptedException, ClassNotFoundException {

		Map<String, ClusterPack> toReturn = new HashMap<String, ClusterPack>();

		int k = numbOfClusters;

		List<Vector> vectors = getPointsFromFile(filename);

		File testData = new File("testdata");

		if (!testData.exists()) {

		testData = new File("testdata/points");

		if (!testData.exists()) {

		Configuration conf = new Configuration();
		FileSystem fs = FileSystem.get(conf);
		ClusterHelper.writePointsToFile(vectors, conf, new Path(

		Path path = new Path("testdata/clusters/part-00000");
		SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, path,
				Text.class, Kluster.class);

		for (int i = 0; i < k; i++) {
			Vector vec = vectors.get(i);
			Kluster cluster = new Kluster(vec, i,
					new EuclideanDistanceMeasure());
			writer.append(new Text(cluster.getIdentifier()), cluster);

		Path output = new Path("output");
		HadoopUtil.delete(conf, output);, new Path("testdata/points"), new Path(
				"testdata/clusters"), output, 0.001, 10, true, 0.0, false);

		SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(
				"output/" + Kluster.CLUSTERED_POINTS_DIR + "/part-m-00000"),

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

		while (, value)) {
	            // ADD SOMETHING HERE !!!

View raw message