如何计算聚类的基尼系数

How to calculate Gini coefficients for clustering

我有 5000 个观察值,这些观察值分为 10 个簇。每个集群有 1000 个真实观察值。每个集群中的真实生活观察为 1000。然而,在我有了 运行 我的聚类算法之后,它看起来像这样:

Cluster #, true members, clustered members
0,                 1000,               435
1,                 1000,               234
2,                 1000,               167
3,                 1000,               654
4,                 1000,                 0

换句话说,集群 0 应该有 1000 个成员,但其中只有 435 个成员被我的算法正确添加到该集群。 5000和簇内的差分放错簇

我想计算基尼系数,找到如下代码:

def gini_ind(Number, Total):
    return (1-(((Number/Total)**2)+(((Total-Number)/Total)**2)))

在我试过的测试中它似乎工作正常。但是,我发现没有一个数据集与我的相似。

所以我的问题是如何计算基尼系数?

如果我执行以下操作,我将获得每个集群的这些基尼系数:

gini_ind(435,1000) -> 0.49155
gini_ind(234,1000) -> 0.3584
gini_ind(167,1000) -> 0.2782
gini_ind(654,1000) -> 0.4525
gini_ind(0,1000) -> 0

这是每个集群的正确基尼系数吗?

并得到平均基尼系数;这只是平均值吗: (0.49155+0.3584+0.2782+0.4525+0)/5 ?

假设我们有 3 classes 和 80 个对象。 class 1 中有 19 个对象,class 2 中有 21 个对象,class 3 中有 40 个对象(表示为 (19,21,40))。

基尼系数为:1- [ (19/80)^2 + (21/80)^2 + (40/80)^2] = 0.6247 即 costbefore = Gini(19,21,40 ) = 0.6247

为了决定在哪里拆分,我们测试了所有可能的拆分。例如在 2.0623 处拆分,结果拆分为 (16,9,0) 和 (3,12,40):

测试后 x1 < 2.0623:

costL =Gini(16,9,0) = 0.4608
costR =Gini(3,12,40) = 0.4205

然后我们通过经验分支概率对分支杂质进行加权:

costx1<2.0623 = 25/80 costL + 55/80 costR = 0.4331

我们对每个可能的拆分都这样做,例如 x1 < 1:

costx1<1 = FractionL Gini(8,4,0) + FractionR Gini(11,17,40) = 12/80 * 0.4444 + 68/80 * 0.5653 = 0.5417

之后,我们选择了成本最低的拆分。这是拆分 x1 < 2.0623,成本为 0.4331。

您可以点击以下链接.... http://dni-institute.in/blogs/gini-index-work-out-example/ http://stats.stackexchange.com/questions/95839/gini-decrease-and-gini-impurity-of-children-nodes