在 Apache Spark Python 中自定义 K-means 的距离公式 [英] Customize Distance Formular of K-means in Apache Spark Python

查看:25
本文介绍了在 Apache Spark Python 中自定义 K-means 的距离公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我使用 K-means 进行聚类并遵循 本教程API.

Now I'm using K-means for clustering and following this tutorial and API.

但我想使用自定义公式来计算距离.那么如何使用 PySpark 在 k-means 中传递自定义距离函数?

But I want to use custom formula for calculate distances. So how can I pass custom distance functions in k-means with PySpark?

推荐答案

通常使用不同的距离度量没有意义,因为 k-means(与 k-medoids) 算法仅适用于欧几里得距离.

In general using a different distance measure doesn't make sense, because k-means (unlike k-medoids) algorithm is well defined only for Euclidean distances.

有关解释,请参阅为什么 k-means 聚类算法仅使用欧几里得距离度量?.

此外,MLlib 算法在 Scala 中实现,PySpark 仅提供执行 Scala 代码所需的包装器.因此,如果 API 没有重大变化,将自定义指标作为 Python 函数提供在技术上是不可能的.

Moreover MLlib algorithms are implemented in Scala, and PySpark provides only the wrappers required to execute Scala code. Therefore providing a custom metric as a Python function, wouldn't be technically possible without significant changes in the API.

请注意,自 Spark 2.4 起,有两个内置度量可与 pyspark.ml.clustering.KMeanspyspark.ml.clustering.BisectingKMeans.(参见<代码>参数).

Please note that since Spark 2.4 there are two built-in measures that can be used with pyspark.ml.clustering.KMeans and pyspark.ml.clustering.BisectingKMeans. (see DistanceMeasure Param).

  • 欧几里得距离.
  • 余弦距离的余弦.

使用风险自负.

这篇关于在 Apache Spark Python 中自定义 K-means 的距离公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆