全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 数据分析与数据挖掘
1238 6
2023-08-03
悬赏 100 个论坛币 已解决
如何使用R或者python或者minitab等软件计算Jaccard系数。

数据详见附件。

请提供相关代码。

谢谢啦。

test.xlsx

大小:32.73 KB

 马上下载

最佳答案

olympic 查看完整内容

Jaccard系数是两个集合之间的相似性度量,定义为两个集合的交集与并集的比例。因此,如果我们有两个集合 A、B,则Jaccard系数为: Jaccard系数=∣A∩B∣/∣A∪B∣。数据80列/组,每一列可能代表一个集合,0和1可能分别代表元素的缺失和存在。80个集合,总共会有 80 ×79/2=3160 个不同的配对。 jaccard_coefficients_df.head() 部分结果 RESULT Set1 Set2 Jaccard Similarity 0 X1 X2 0.155556 1 X1 ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2023-8-3 21:08:08
Jaccard系数是两个集合之间的相似性度量,定义为两个集合的交集与并集的比例。因此,如果我们有两个集合 A、B,则Jaccard系数为:
Jaccard系数=∣A∩B∣/∣A∪B∣。数据80列/组,每一列可能代表一个集合,0和1可能分别代表元素的缺失和存在。80个集合,总共会有 80
×79/2=3160 个不同的配对。

jaccard_coefficients_df.head()
部分结果 RESULT
  Set1 Set2  Jaccard Similarity
0   X1   X2            0.155556
1   X1   X3            0.140000
2   X1   X4            0.173913
3   X1   X5            0.129630
4   X1   X6            0.090909
附件列表

jaccard.zip

大小:25.02 KB

只需: 100 个论坛币  马上下载

Jaccard系数.py

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2023-8-8 11:03:59
def jaccard(xs:set, ys:set):
    M = len(xs.intersection(ys))
    N = len(xs.union(ys))
    return float(M/N)
# Example:
xs = set(range(1, 10))
ys = set(range(5, 15))
jaccard(xs, ys)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2023-8-8 11:05:03
def jaccard(xs:set, ys:set):
    M = len(xs.intersection(ys))
    N = len(xs.union(ys))
    return float(M/N)
# Example:
xs = set(range(1, 10))
ys = set(range(5, 15))
jaccard(xs, ys)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2023-8-9 16:00:37
The Jaccard index, also known as the Jaccard similarity coefficient, is a statistic used for comparing the similarity and diversity of sample sets. It's defined as the size of the intersection divided by the size of the union of the sample sets.

Here is a simple Python function that calculates the Jaccard similarity between two sets:
def jaccard_similarity(set1, set2):
    intersection = len(set1.intersection(set2))
    union = len(set1) + len(set2) - intersection
    return intersection / union

You can use this function like so:
set1 = set(['dog', 'cat', 'bird'])
set2 = set(['cat', 'bird', 'fish'])
print(jaccard_similarity(set1, set2))  # Output: 0.5

This means that the two sets share 50% similarity according to the Jaccard index.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2023-8-23 09:46:36
在R语言中,可以使用proxy包的dist.binary函数来计算Jaccard系数。

计算Jaccard系数的具体步骤如下:

1. 引入proxy包:

```r
library(proxy)
```

2. 准备输入的0-1矩阵,矩阵中的1表示集合中存在该元素,0表示不存在。

3. 使用dist.binary函数计算矩阵之间的距离,方法选择"jaccard"。

4. 返回的距离矩阵即为各集合组合之间的Jaccard系数。

例如:

```r
set1 <- c(1,0,1,1,0)
set2 <- c(0,1,0,1,1)
mat <- rbind(set1, set2)

dist_mat <- dist.binary(mat, method="jaccard")

# 输出距离矩阵
dist_mat
           1
2 0.6666667
```

距离为0.67,即两集合之间的Jaccard系数为0.67。

所以使用proxy::dist.binary可以非常方便地计算Jaccard系数。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群