首页 > 代码库 > 计算簇间距离

计算簇间距离

<strong><span style="font-size:18px;">/***
 * @author YangXin
 * @info 计算簇间距
 */
package unitTen;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Writable;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.common.distance.CosineDistanceMeasure;
import org.apache.mahout.common.distance.DistanceMeasure;
public class InterClusterDistances {
	 public static void main(String args[]) throws Exception {
		    
		    String inputFile = "reuters-kmeans-clusters/clusters-6/part-r-00000";
		    
		    Configuration conf = new Configuration();
		    Path path = new Path(inputFile);
		    System.out.println("Input Path: " + path);
		    FileSystem fs = FileSystem.get(path.toUri(), conf);
		    
		    List<Cluster> clusters = new ArrayList<Cluster>();
		    
		    SequenceFile.Reader reader = new SequenceFile.Reader(
		        fs, path, conf);
		    Writable key = (Writable) reader.getKeyClass()
		        .newInstance();
		    Writable value = http://www.mamicode.com/(Writable) reader.getValueClass()"Maximum Intercluster Distance: "
		                       + max);
		    System.out.println("Minimum Intercluster Distance: "
		                       + min);
		    System.out
		        .println("Average Intercluster Distance(Scaled): "
		                 + (sum / count - min) / (max - min));
		  }
}
</span></strong>

计算簇间距离