Exemple #1
0
    def test_prunning(self):
        pruned = hierarchical.prune(self.cluster, level=2)
        depths = hierarchical.cluster_depths(pruned)
        self.assertTrue(all(d <= 2 for d in depths.values()))

        pruned = hierarchical.prune(self.cluster, height=10)
        self.assertTrue(c.height >= 10 for c in hierarchical.preorder(pruned))

        top = hierarchical.top_clusters(self.cluster, 3)
        self.assertEqual(len(top), 3)

        top = hierarchical.top_clusters(self.cluster, len(self.matrix))
        self.assertEqual(len(top), len(self.matrix))
        self.assertTrue(all(n.is_leaf for n in top))

        top1 = hierarchical.top_clusters(self.cluster, len(self.matrix) + 1)
        self.assertEqual(top1, top)
    def test_prunning(self):
        pruned = hierarchical.prune(self.cluster, level=2)
        depths = hierarchical.cluster_depths(pruned)
        self.assertTrue(all(d <= 2 for d in depths.values()))

        pruned = hierarchical.prune(self.cluster, height=10)
        self.assertTrue(c.height >= 10 for c in hierarchical.preorder(pruned))

        top = hierarchical.top_clusters(self.cluster, 3)
        self.assertEqual(len(top), 3)

        top = hierarchical.top_clusters(self.cluster, len(self.matrix))
        self.assertEqual(len(top), len(self.matrix))
        self.assertTrue(all(n.is_leaf for n in top))

        top1 = hierarchical.top_clusters(self.cluster, len(self.matrix) + 1)
        self.assertEqual(top1, top)
 def test_example_clustering_on(self, data):
     constructors = [Euclidean, Manhattan]
     for distance_constructor in constructors:
         clust = clustering(data, distance_constructor, HierarchicalClustering.Single)
         clust = clustering(data, distance_constructor, HierarchicalClustering.Average)
         clust = clustering(data, distance_constructor, HierarchicalClustering.Complete)
         clust = clustering(data, distance_constructor, HierarchicalClustering.Ward)
         top_clust = top_clusters(clust, 5)
         cluster_list = cluster_to_list(clust, 5)
Exemple #4
0
 def test_example_clustering_on(self, data):
     constructors = [Euclidean, Manhattan]
     for distance_constructor in constructors:
         clust = clustering(data, distance_constructor,
                            HierarchicalClustering.Single)
         clust = clustering(data, distance_constructor,
                            HierarchicalClustering.Average)
         clust = clustering(data, distance_constructor,
                            HierarchicalClustering.Complete)
         clust = clustering(data, distance_constructor,
                            HierarchicalClustering.Ward)
         top_clust = top_clusters(clust, 5)
         cluster_list = cluster_to_list(clust, 5)
 def select_top_n(self, n):
     root = self._displayed_root
     if root:
         clusters = top_clusters(root, n)
         self.dendrogram.set_selected_clusters(clusters)
 def select_top_n(self, n):
     root = self._displayed_root
     if root:
         clusters = top_clusters(root, n)
         self.dendrogram.set_selected_clusters(clusters)