File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -974,7 +974,7 @@ def davies_bouldin(
974
974
:type clusters: List[List[int]]
975
975
:param dist_kwargs: kwargs for the distance function, defaults to {}
976
976
:type dist_kwargs: dict, optional
977
- :return: TheDavies -Bouldin (DB) index
977
+ :return: The Davies -Bouldin (DB) index
978
978
:rtype: float
979
979
"""
980
980
k = len (clusters )
@@ -1001,15 +1001,28 @@ def davies_bouldin(
1001
1001
X , clusters , all = True , dist_kwargs = dist_kwargs
1002
1002
)
1003
1003
1004
- DB_aux = [
1005
- np .amax ([
1004
+ # Compute R_ijs even when i=j
1005
+ R_ijs = [
1006
+ [
1006
1007
(S_is [i ] + S_is [j ]) / dist_between_centroids [i ][j ]
1007
1008
if dist_between_centroids [i ][j ] != 0 else np .inf
1008
1009
for j in range (k )
1009
- ]) for i in range (k )
1010
+ ] for i in range (k )
1011
+ ]
1012
+
1013
+ # Remove the case i == j as described in the paper
1014
+ R_ijs = [
1015
+ [
1016
+ R_ijs [i ][j ] for j in range (k ) if i != j
1017
+ ] for i in range (k )
1018
+ ]
1019
+
1020
+ # Compute R_is = max_j of R_ijs when i != j
1021
+ R_is = [
1022
+ np .amax (R_ijs ) for i in range (k )
1010
1023
]
1011
1024
1012
- DB = (1 / k ) * np .sum (DB_aux )
1025
+ DB = (1 / k ) * np .sum (R_is )
1013
1026
DB = float (DB )
1014
1027
1015
1028
return DB
You can’t perform that action at this time.
0 commit comments