@@ -244,7 +244,7 @@ def similarityMeasurement(matrix, vector, method='euclidean'):
244
244
if method == 'sqeuclidean' :
245
245
return euclideanDistance (matrix , vector , True )
246
246
247
- spatialMethods = ['cityblock' , 'chebyshev' , 'canberra' , 'correlation' , 'hamming' , 'mahalanobis' , 'correlation' ]
247
+ spatialMethods = ['cityblock' , 'chebyshev' , 'canberra' , 'correlation' , 'hamming' , 'mahalanobis' ,]
248
248
249
249
if method in spatialMethods :
250
250
return cdist (matrix , np .atleast_2d (vector ), method ).flatten ()
@@ -376,7 +376,7 @@ def similarityMeasurementMatrix(matrix, method):
376
376
return euclideanDistanceMatrix (matrix , True )
377
377
# return squareform(pdist(matrix, method))
378
378
379
- spatialMethods = ['cityblock' , 'chebyshev' , 'canberra' , 'correlation' , 'hamming' , 'mahalanobis' , 'correlation' ]
379
+ spatialMethods = ['cityblock' , 'chebyshev' , 'canberra' , 'correlation' , 'hamming' , 'mahalanobis' ]
380
380
381
381
if method in spatialMethods :
382
382
return squareform (pdist (matrix , method ))
@@ -411,12 +411,19 @@ def computeClusterInternDistances(matrix, labels, sorted=True, metric='euclidean
411
411
# compute distances to centroid
412
412
dists = similarityMeasurement (subMatrix , centroid , metric )
413
413
414
- if sorted :
414
+ if sorted == 'true' :
415
415
# sort values
416
416
indices = range (len (dists ))
417
417
indices .sort (key = dists .__getitem__ )
418
418
dists .sort ()
419
419
420
+ # reverse order if correlation coefficient is used
421
+ # (1 means perfect correlation while -1 denotes opposite correlation)
422
+ corrMetrics = ['pearson' , 'spearman' , 'kendall' ]
423
+ if metric in corrMetrics :
424
+ indices .reverse ()
425
+ dists = dists [::- 1 ]
426
+
420
427
# write back to our arrays
421
428
distLabels = clusterLabels [indices ].tolist ()
422
429
distValues = dists .tolist ()
0 commit comments