我正在使用 Python 中的 kmodes.kprototypes 对混合(数字和分类)类型数据进行聚类:
from kmodes.kprototypes import KPrototypes
kp = KPrototypes(n_clusters=5, init='Cao')
kp.fit(df, categorical=categorical_column_list)
完成后,我想评估/比较结果。当我处理混合类型数据时,我无法使用任何 sklearn 常用的聚类评估方法(据我了解,它们仅适用于数值数据)。相反,KPrototypes 提供了内置的
.cost_
属性,具有某种聚合相似性(它的 源代码文档字符串 声明它“定义为所有点到各自簇质心的总距离”)。
我不知道如何解释这笔费用。基于我对代码的理解很差,它确实是每个数据点的距离值的汇总,但这意味着
n_clusters
越高,cost_
就越低(事实上,这是趋势)在极端(但荒谬)的情况下 n_clusters = len(X)
cost_
将是最低的。
这里
cost_
到底是什么?它可以用于平常的评估吗?如果不是,这里使用什么指标?
Kmodes/KPrototype 算法的
cost_
属性测量分类对象与相应模式/质心之间的差异。这通常是使用像Hamming Distance这样的方法来完成的。汉明距离的直观例子:
For any two objects (say, A and B) in the dataset, the Hamming distance is the number of attributes for which A and B have different categories. For instance, if A = (Red, Small, Circle) and B = (Blue, Small, Square), the Hamming distance between A and B is 2, since they differ in color and shape.
那么成本就是数据点和集群模式的不相似性。
在评估方面,
cost_
属性可以用于一些不同的事情:
仅举几例。
希望有帮助。