Distance metric in fastclluster Python module

I want to perform hierarchical clustering with the fastcluster module. When I am the default distance metric (Euclidean), it works fine:

import fastcluster import scipy.cluster.hierarchy distance = spatial.distance.pdist(data) linkage = fastcluster.linkage(distance,method="complete") 

But the problem is that I want to use the "cosine similarity" as a distance metric:

 distance = spatial.distance.pdist(data,'cosine') linkage = fastcluster.linkage(distance,method="complete") 

Output:

 Traceback (most recent call last): File "C:\djcode\mysite\mysite\scipytest.py", line 52, in <module> linkage = fastcluster.linkage(distance,method="complete") File "C:\Python33\lib\site-packages\fastcluster.py", line 245, in linkage linkage_wrap(N, X, Z, mthidx[method]) FloatingPointError: NaN dissimilarity value. 
+7
python scipy hierarchical-clustering
source share

No one has answered this question yet.

See related questions:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a "contains" substring method?
3119
What is the difference between Python list methods that are added and expanded?
2818
Finding an index of an element with a list containing it in Python
2601
How can I make a time delay in Python?
2568
How to find out the current time in Python
2097
Is there a way to run Python on Android?

All Articles