Package org.apache.mahout.clustering.kmeans

Examples of org.apache.mahout.clustering.kmeans.Cluster


    SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf,
        path, Text.class, Cluster.class);
   
    for (int i = 0; i < k; i++) {
      Vector vec = vectors.get(i);
      Cluster cluster = new Cluster(vec, i, new EuclideanDistanceMeasure());
      writer.append(new Text(cluster.getIdentifier()), cluster);
    }
    writer.close();
   
    KMeansDriver.run(conf, new Path("testdata/points"), new Path("testdata/clusters"),
      new Path("output"), new EuclideanDistanceMeasure(), 0.001, 10,
View Full Code Here


    reader.close();
    List<Canopy> canopies = CanopyClusterer.createCanopies(points, new CosineDistanceMeasure(), 0.8, 0.7);
    List<Cluster> clusters = new ArrayList<Cluster>();
    System.out.println(canopies.size());
    for (Canopy canopy : canopies) {
      clusters.add(new Cluster(canopy.getCenter(), canopy.getId(), new CosineDistanceMeasure()));
    }
  }
View Full Code Here

        sampleData, k);
    List<Cluster> clusters = new ArrayList<Cluster>();

    int clusterId = 0;
    for (Vector v : randomPoints) {
      clusters.add(new Cluster(v, clusterId++, new EuclideanDistanceMeasure()));
    }

    List<List<Cluster>> finalClusters = KMeansClusterer.clusterPoints(
        sampleData, clusters, new EuclideanDistanceMeasure(), 3, 0.01);
    for (Cluster cluster : finalClusters.get(finalClusters.size() - 1)) {
View Full Code Here

  
    List<Canopy> canopies = CanopyClusterer.createCanopies(points, new CosineDistanceMeasure(), 0.7, 0.5);
    List<Cluster> clusters = new ArrayList<Cluster>();
    System.out.println(canopies.size());
    for (Canopy canopy : canopies) {
      clusters.add(new Cluster(canopy.getCenter(), canopy.getId(), new CosineDistanceMeasure()));
    }
   
    List<List<Cluster>> finalClusters = KMeansClusterer.clusterPoints(points, clusters,
      new CosineDistanceMeasure(), 10, 0.1);
    for (Cluster cluster : finalClusters.get(finalClusters.size() - 1)) {
View Full Code Here

    List<Vector> randomPoints = RandomPointsUtil.chooseRandomPoints(points, k);
    List<Cluster> clusters = new ArrayList<Cluster>();
    System.out.println(randomPoints.size());
    int clusterId = 0;
    for (Vector v : randomPoints) {
      clusters.add(new Cluster(v, clusterId++, new CosineDistanceMeasure()));
    }
   
    List<List<Cluster>> finalClusters = KMeansClusterer.clusterPoints(points, clusters,
      new CosineDistanceMeasure(), 10, 0.01);
    for (Cluster cluster : finalClusters.get(finalClusters.size() - 1)) {
View Full Code Here

  }

  public void testClusterAsFormatString() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    Printable cluster = new Cluster(m, 123);
    String formatString = cluster.asFormatString(null);
    System.out.println(formatString);
    assertEquals("format", "C123: [1.100, 2.200, 3.300]", formatString);
  }
View Full Code Here

  public void testClusterAsFormatStringSparse() {
    double[] d = { 1.1, 0.0, 3.3 };
    Vector m = new SequentialAccessSparseVector(3);
    m.assign(d);
    Printable cluster = new Cluster(m, 123);
    String formatString = cluster.asFormatString(null);
    System.out.println(formatString);
    assertEquals("format", "C123: [0:1.100, 2:3.300]", formatString);
  }
View Full Code Here

  }

  public void testClusterAsFormatStringWithBindings() {
    double[] d = { 1.1, 2.2, 3.3 };
    Vector m = new DenseVector(d);
    Printable cluster = new Cluster(m, 123);
    String[] bindings = { "fee", null, "foo" };
    String formatString = cluster.asFormatString(bindings);
    System.out.println(formatString);
    assertEquals("format", "C123: [fee:1.100, 1:2.200, foo:3.300]", formatString);
  }
View Full Code Here

  public void testClusterAsFormatStringSparseWithBindings() {
    double[] d = { 1.1, 0.0, 3.3 };
    Vector m = new SequentialAccessSparseVector(3);
    m.assign(d);
    Printable cluster = new Cluster(m, 123);
    String formatString = cluster.asFormatString(null);
    System.out.println(formatString);
    assertEquals("format", "C123: [0:1.100, 2:3.300]", formatString);
  }
View Full Code Here

          } catch (IllegalAccessException e) {
            log.error("Exception", e);
            throw new IllegalStateException(e);
          }
          if (valueClass.equals(Cluster.class)) {
            Cluster value = new Cluster();
            while (reader.next(key, value)) {
              // get the cluster info
              SoftCluster theCluster = new SoftCluster(value.getCenter(), value.getId());
              clusters.add(theCluster);
              value = new Cluster();
            }
          } else if (valueClass.equals(SoftCluster.class)) {
            SoftCluster value = new SoftCluster();
            while (reader.next(key, value)) {
              // get the cluster info
View Full Code Here

TOP

Related Classes of org.apache.mahout.clustering.kmeans.Cluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.