org.apache.spark.mllib.clustering.KMeans.setMaxIterations()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.apache.spark.mllib.clustering.KMeans.setMaxIterations()方法的一些代码示例,展示了KMeans.setMaxIterations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KMeans.setMaxIterations()方法的具体详情如下:
包路径:org.apache.spark.mllib.clustering.KMeans
类名称:KMeans
方法名:setMaxIterations

KMeans.setMaxIterations介绍

暂无

代码示例

代码示例来源:origin: locationtech/geowave

kmeans.setInitializationMode("kmeans||");
kmeans.setK(numClusters);
kmeans.setMaxIterations(numIterations);

代码示例来源:origin: org.apache.spark/spark-mllib

@Test
 public void testPredictJavaRDD() {
  List<Vector> points = Arrays.asList(
   Vectors.dense(1.0, 2.0, 6.0),
   Vectors.dense(1.0, 3.0, 0.0),
   Vectors.dense(1.0, 4.0, 6.0)
  );
  JavaRDD<Vector> data = jsc.parallelize(points, 2);
  KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
  JavaRDD<Integer> predictions = model.predict(data);
  // Should be able to get the first prediction.
  predictions.first();
 }
}

代码示例来源:origin: org.apache.spark/spark-mllib_2.11

@Test
 public void testPredictJavaRDD() {
  List<Vector> points = Arrays.asList(
   Vectors.dense(1.0, 2.0, 6.0),
   Vectors.dense(1.0, 3.0, 0.0),
   Vectors.dense(1.0, 4.0, 6.0)
  );
  JavaRDD<Vector> data = jsc.parallelize(points, 2);
  KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
  JavaRDD<Integer> predictions = model.predict(data);
  // Should be able to get the first prediction.
  predictions.first();
 }
}

代码示例来源:origin: org.apache.spark/spark-mllib_2.10

@Test
 public void testPredictJavaRDD() {
  List<Vector> points = Arrays.asList(
   Vectors.dense(1.0, 2.0, 6.0),
   Vectors.dense(1.0, 3.0, 0.0),
   Vectors.dense(1.0, 4.0, 6.0)
  );
  JavaRDD<Vector> data = jsc.parallelize(points, 2);
  KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
  JavaRDD<Integer> predictions = model.predict(data);
  // Should be able to get the first prediction.
  predictions.first();
 }
}

代码示例来源:origin: org.apache.spark/spark-mllib_2.11

@Test
public void runKMeansUsingConstructor() {
 List<Vector> points = Arrays.asList(
  Vectors.dense(1.0, 2.0, 6.0),
  Vectors.dense(1.0, 3.0, 0.0),
  Vectors.dense(1.0, 4.0, 6.0)
 );
 Vector expectedCenter = Vectors.dense(1.0, 3.0, 4.0);
 JavaRDD<Vector> data = jsc.parallelize(points, 2);
 KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
 assertEquals(1, model.clusterCenters().length);
 assertEquals(expectedCenter, model.clusterCenters()[0]);
 model = new KMeans()
  .setK(1)
  .setMaxIterations(1)
  .setInitializationMode(KMeans.RANDOM())
  .run(data.rdd());
 assertEquals(expectedCenter, model.clusterCenters()[0]);
}

代码示例来源:origin: org.apache.spark/spark-mllib_2.10

@Test
public void runKMeansUsingConstructor() {
 List<Vector> points = Arrays.asList(
  Vectors.dense(1.0, 2.0, 6.0),
  Vectors.dense(1.0, 3.0, 0.0),
  Vectors.dense(1.0, 4.0, 6.0)
 );
 Vector expectedCenter = Vectors.dense(1.0, 3.0, 4.0);
 JavaRDD<Vector> data = jsc.parallelize(points, 2);
 KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
 assertEquals(1, model.clusterCenters().length);
 assertEquals(expectedCenter, model.clusterCenters()[0]);
 model = new KMeans()
  .setK(1)
  .setMaxIterations(1)
  .setInitializationMode(KMeans.RANDOM())
  .run(data.rdd());
 assertEquals(expectedCenter, model.clusterCenters()[0]);
}

代码示例来源:origin: org.apache.spark/spark-mllib

@Test
public void runKMeansUsingConstructor() {
 List<Vector> points = Arrays.asList(
  Vectors.dense(1.0, 2.0, 6.0),
  Vectors.dense(1.0, 3.0, 0.0),
  Vectors.dense(1.0, 4.0, 6.0)
 );
 Vector expectedCenter = Vectors.dense(1.0, 3.0, 4.0);
 JavaRDD<Vector> data = jsc.parallelize(points, 2);
 KMeansModel model = new KMeans().setK(1).setMaxIterations(5).run(data.rdd());
 assertEquals(1, model.clusterCenters().length);
 assertEquals(expectedCenter, model.clusterCenters()[0]);
 model = new KMeans()
  .setK(1)
  .setMaxIterations(1)
  .setInitializationMode(KMeans.RANDOM())
  .run(data.rdd());
 assertEquals(expectedCenter, model.clusterCenters()[0]);
}

相关文章