简体   繁体   English

Jaccard距离 - 联合和列表的交集

[英]Jaccard distance - union and intersection of lists

I am implementing hierarchical clustering using Jaccard distance. 我正在使用Jaccard距离实现层次聚类。 The transactions for which I am trying to find Jaccard are represented in binary. 我试图找到Jaccard的交易以二进制表示。 For eg.: 例如:

t1=['0','1','1','0','1']

t2=['1','0','1','0','0'] . t2=['1','0','1','0','0']

I looked at this SO question , which is very similar to what I want, but I am not getting the right answer. 我看了这个问题 ,这与我想要的非常相似,但我得不到正确的答案。

Basically this is what I am looking for: 基本上这就是我要找的东西:
1. find intersection and union for the above 2 lists. 1.找到上述2个列表的交集和并集。

I have tried the below apart from looking at numerous other online resources: 除了查看其他众多在线资源外,我还尝试了以下内容:

1. s1=sets.Set(['0','1','1','0','1'])
   s2=sets.Set(['1','0','1','0','0'])  
2. s1.intersection(s2)  ---> Set(['1', '0'])  
   s1.union(s2)         ---> Set(['1', '0'])  
3. Set(s1) & Set(s2)      ---> TypeError: unsupported operand type(s) for /: 'Set' and 'Set'

   Set(s1) | Set(s2)

Please guide me. 请指导我。

Thanks. 谢谢。

As you said: 如你所说:

s1=sets.Set(['0','1','1','0','1'])

Let's check s1: 我们来看看s1:

print s1
---->Set(['1', '0'])

sets module provides classes for constructing and manipulating unordered collections of unique elements. sets模块提供了用于构造和操作独特元素的无序集合的类。 So, your s1 and s2 are actually the same. 所以,你的s1和s2实际上是一样的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM