k-均值|| 在 PySpark 中

数据挖掘 机器学习 k-均值 pyspark
2021-10-02 16:57:51

我正在尝试应用 k-meansPySpark 中的聚类。

根据这篇论文,有一个过采样因子,l,这会影响模型的成本。

我在 PySpark 的 k-means 函数中找不到任何关于过采样因子的参数。有一个参数被调用initializationSteps,但没有适当的定义。

有没有办法可以在 k-means 函数中使用过采样因子?

2个回答

根据您设置 k 但想要采样大于 k 并应用对数计算的论文。

我建议使用 foreach 函数。你可以说 foreach() 应用比 k 更远的范围。

论文中的以下 aglo 可以解释如下。

算法 2 k-means||(k, ) 初始化。

1: C ← sample a point uniformly at random from X
2: ψ ← φX(C)
3: for O(log ψ) times do
4: C 0 ← sample each point x ∈ X independently with probability px =·d2(x,C) φX(C)
5: C ← C ∪ C0
6: end for
7: For x ∈ C, set wx to be the number of points in X closer to x than any other point inC
8: Recluster the weighted points in C into k clusters

指示:

get points of k = 2
points [(1,1),(1,2),(2,2)]

本示例的质心位于中间,并且

c1 = [(1,1),(1,2)]

foreach()这是通过满足过采样要求的欧几里得点的过采样来实现的。

请参阅此处的示例,该示例用于每个:

# Cluster the data into two classes using PowerIterationClustering
model = PowerIterationClustering.train(similarities, 2, 10)

model.assignments().foreach(lambda x: print(str(x.id) + " -> " + str(x.cluster)))

因此,您需要将距离写入 lambda。(如果您提供更容易帮助您的代码)。

K 距离 = k 周长距离,即图中底部的红线 在此处输入图像描述

 .foreach(lambda x: kdistance[get average] + then check prob(k prime) of k)

请分享一些代码和示例数据

希望这篇文章能给你一个相同的开端。