本文主要是介绍在内存中执行k-means聚类算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<strong><span style="font-size:18px;">/**** @author YangXin* @info 利用点集测试K-Means聚类算法*/
package unitNine;
import java.util.ArrayList;
import java.util.List;
import org.apache.mahout.clustering.Cluster;
import org.apache.mahout.clustering.UncommonDistributions;
import org.apache.mahout.common.distance.EuclideanDistanceMeasure;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;
public class KMeansExample {private static void generateSamples(List<Vector> vectors, int num, double mx, double my, double sd){for(int i = 0; i < num; i++){vectors.add(new DenseVector(new double[]{UncommonDistributions.rNorm(mx, sd),UncommonDistributions.rNorm(my, sd) }));}}public static void main(String[] args){List<Vector> sampleData = new ArrayList<Vector>();RandomPointsUtil.generateSamples(sampleData, 400, 1, 1, 3);RandomPointsUtil.generateSamples
这篇关于在内存中执行k-means聚类算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!