K-Means||算法原理为:(在基于Spark MLlib中的K-Means算法初始化K个类簇中心时的方法之一,另一种是随机选取K个中心)
1.为每个run的K-Means随机选择一个初中心点,然后再平均随机选择2k个点,每个点被选择的概率和该点到类簇中心的距离成正比;
2.对选出的这2k个点做一次K-Means++,找出k个初始化类簇中心,在这2k个左右的点上基于k初始化类簇中心执行多次Lloyd算法;
3.得到的类簇中心作为最终的初始化类簇中心。
K-Means++算法原理为:(初始的聚类中心之间的相互距离要尽可能的远)
1.从输入的数据点集合中随机选择一个点作为第一个聚类中心;
2.对于数据集中的每一个点X,计算其与聚类中心的距离D(X);
3.选择一个D(X)最大的点作为新的聚类中心;
4.重复2和3步直到K个聚类中心被选出;
5.利用K个初始聚类中心运行K-Means。
/
最近看了下Spark-1.4.0的官方说明整理了一点东西,估计以后用的到
常用的API:
Transformation:
map(func)、filter(func)、flatMap(func)、mapPartitions(func)、mapPartitionsWithIndex(func)、sample(withReplacement,fraction,seed)、
union(otherDataset)、intersection(otherDAtaset)、distinct(numTasks)、groupByKey(numTasks)、reduceByKey(func,(numTasks))、
aggregateByKey(zeroValue)(Seq op,comb op,【numTasks】)、sortByKey(【ascending】,【numTasks】)、join(otherDataset,【numTasks】)、
Cogroup(otherDataset,【numTasks】)、cartesian(otherDataset)、pipe(command,【envVers】)、coalesce(numParititions)、
repartition(numParititions)、repartitionAndSortWithinPartitions(partitions)
Actions:
reduce(func)、collect()、count()、first()、take(n)、takeSample(withReplacement,num,【seed】)、takeOrdered(n,【ordering】)、
saveAsTestFile(path)、saveAsSequenceFile(path)、saveAsObjectFile(path)、CountByKey()、foreach(func)
///
Accumulators:
创建一个累加器从一个初始值v通过调用SparkContext.accumulator(v)。任务在集群上运行就可以添加使用add或者+=操作符(在Scala和Python)。然而,他们不能读accumulator的值。只有运行程序时可