當前位置: 首頁>>代碼示例>>Java>>正文


Java KMeansData類代碼示例

本文整理匯總了Java中org.apache.flink.examples.java.clustering.util.KMeansData的典型用法代碼示例。如果您正苦於以下問題:Java KMeansData類的具體用法?Java KMeansData怎麽用?Java KMeansData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KMeansData類屬於org.apache.flink.examples.java.clustering.util包,在下文中一共展示了KMeansData類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: runKMeans

import org.apache.flink.examples.java.clustering.util.KMeansData; //導入依賴的package包/類
private static void runKMeans(ExecutionEnvironment env) throws Exception {

		env.setParallelism(PARALLELISM);
		env.getConfig().disableSysoutLogging();

		// get input data
		DataSet<KMeans.Point> points =  KMeansData.getDefaultPointDataSet(env).rebalance();
		DataSet<KMeans.Centroid> centroids =  KMeansData.getDefaultCentroidDataSet(env).rebalance();

		// set number of bulk iterations for KMeans algorithm
		IterativeDataSet<KMeans.Centroid> loop = centroids.iterate(20);

		DataSet<KMeans.Centroid> newCentroids = points
				// compute closest centroid for each point
				.map(new KMeans.SelectNearestCenter()).withBroadcastSet(loop, "centroids")
						// count and sum point coordinates for each centroid
				.map(new KMeans.CountAppender())
				.groupBy(0).reduce(new KMeans.CentroidAccumulator())
						// compute new centroids from point counts and coordinate sums
				.map(new KMeans.CentroidAverager());

		// feed new centroids back into next iteration
		DataSet<KMeans.Centroid> finalCentroids = loop.closeWith(newCentroids);

		DataSet<Tuple2<Integer, KMeans.Point>> clusteredPoints = points
				// assign points to final clusters
				.map(new KMeans.SelectNearestCenter()).withBroadcastSet(finalCentroids, "centroids");

		clusteredPoints.output(new DiscardingOutputFormat<Tuple2<Integer, KMeans.Point>>());

		env.execute("KMeans Example");
	}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:33,代碼來源:SuccessAfterNetworkBuffersFailureITCase.java

示例2: getCentroidDataSet

import org.apache.flink.examples.java.clustering.util.KMeansData; //導入依賴的package包/類
private static DataSet<Centroid> getCentroidDataSet(ParameterTool params, ExecutionEnvironment env) {
	DataSet<Centroid> centroids;
	if (params.has("centroids")) {
		centroids = env.readCsvFile(params.get("centroids"))
			.fieldDelimiter(" ")
			.pojoType(Centroid.class, "id", "x", "y");
	} else {
		System.out.println("Executing K-Means example with default centroid data set.");
		System.out.println("Use --centroids to specify file input.");
		centroids = KMeansData.getDefaultCentroidDataSet(env);
	}
	return centroids;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:14,代碼來源:KMeans.java

示例3: getPointDataSet

import org.apache.flink.examples.java.clustering.util.KMeansData; //導入依賴的package包/類
private static DataSet<Point> getPointDataSet(ParameterTool params, ExecutionEnvironment env) {
	DataSet<Point> points;
	if (params.has("points")) {
		// read points from CSV file
		points = env.readCsvFile(params.get("points"))
			.fieldDelimiter(" ")
			.pojoType(Point.class, "x", "y");
	} else {
		System.out.println("Executing K-Means example with default point data set.");
		System.out.println("Use --points to specify file input.");
		points = KMeansData.getDefaultPointDataSet(env);
	}
	return points;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:15,代碼來源:KMeans.java

示例4: getPointDataSet

import org.apache.flink.examples.java.clustering.util.KMeansData; //導入依賴的package包/類
private static DataSet<Point> getPointDataSet(ExecutionEnvironment env) {
	if(fileOutput) {
		// read points from CSV file
		return env.readCsvFile(pointsPath)
					.fieldDelimiter(' ')
					.includeFields(true, true)
					.types(Double.class, Double.class)
					.map(new TuplePointConverter());
	} else {
		return KMeansData.getDefaultPointDataSet(env);
	}
}
 
開發者ID:citlab,項目名稱:vs.msc.ws14,代碼行數:13,代碼來源:KMeans.java

示例5: getCentroidDataSet

import org.apache.flink.examples.java.clustering.util.KMeansData; //導入依賴的package包/類
private static DataSet<Centroid> getCentroidDataSet(ExecutionEnvironment env) {
	if(fileOutput) {
		return env.readCsvFile(centersPath)
					.fieldDelimiter(' ')
					.includeFields(true, true, true)
					.types(Integer.class, Double.class, Double.class)
					.map(new TupleCentroidConverter());
	} else {
		return KMeansData.getDefaultCentroidDataSet(env);
	}
}
 
開發者ID:citlab,項目名稱:vs.msc.ws14,代碼行數:12,代碼來源:KMeans.java


注:本文中的org.apache.flink.examples.java.clustering.util.KMeansData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。