From b7ea0917cbdb0e13228e7a701dde8343f54ee28b Mon Sep 17 00:00:00 2001 From: GLeurquin Date: Wed, 23 Jan 2019 11:10:38 +0100 Subject: [PATCH] Update rtree.py Fixes '>' not supported between instances of '_NodeCursor' and '_NodeCursor', which happens when there are identical silhouette coefficients, as the max method will then try to sort by the nodes, but there is no compare method defined on the nodes. This fix will just select one of the best silhouette coefficients --- pyrtree/rtree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrtree/rtree.py b/pyrtree/rtree.py index a711e2e..453ad36 100644 --- a/pyrtree/rtree.py +++ b/pyrtree/rtree.py @@ -247,7 +247,7 @@ def _balance(self): memo = {} clusterings = [ k_means_cluster(self.root,k,s_children) for k in range(2,MAX_KMEANS) ] - score,bestcluster = max( [ (silhouette_coeff(c,memo),c) for c in clusterings ]) + score,bestcluster = max( [ (silhouette_coeff(c,memo),c) for c in clusterings ], key=lambda x:x[0]) nodes = [ _NodeCursor.create_with_children(c,self.root) for c in bestcluster if len(c) > 0]