From 8f5acde44c9708c905e95ad686258ba2bd5ae98c Mon Sep 17 00:00:00 2001 From: Dantali0n Date: Wed, 10 Jun 2020 18:06:56 +0200 Subject: [PATCH] Fix 'NonHierarchicalClustering' object has no attribute 'ranges' ch5 In chapter 5 method compute_distance_matrix_instances the attribute self.ranges is accessed but this is unset. The cause is that ranges above is set as variable within the scope of the current method but since this is not the constructor of the class it does not actually set self.ranges. This in turn causes the subsequent access to result in an AttributeError. --- Python3Code/Chapter5/Clustering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python3Code/Chapter5/Clustering.py b/Python3Code/Chapter5/Clustering.py index 71284a65..87b73cba 100755 --- a/Python3Code/Chapter5/Clustering.py +++ b/Python3Code/Chapter5/Clustering.py @@ -145,7 +145,7 @@ def compute_distance_matrix_instances(self, dataset, distance_metric): DM = InstanceDistanceMetrics() # Define the ranges of the columns if we use the gower distance. - ranges = [] + self.ranges = [] if distance_metric == self.gower: for col in dataset.columns: self.ranges.append(dataset[col].max() - dataset[col].min())