楼主: peaktang
1237 6

[数据挖掘理论与案例] 坐等:如何使用R或者python或者minitab等软件计算Jaccard系数 [推广有奖]

  • 0关注
  • 0粉丝

小学生

7%

还不是VIP/贵宾

-

威望
0
论坛币
305 个
通用积分
0.3100
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
63 点
帖子
2
精华
0
在线时间
7 小时
注册时间
2015-1-1
最后登录
2024-5-13

楼主
peaktang 在职认证  发表于 2023-8-3 21:08:07 |AI写论文
100论坛币
如何使用R或者python或者minitab等软件计算Jaccard系数。

数据详见附件。

请提供相关代码。

谢谢啦。

最佳答案

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 ...
关键词:Jaccard MiniTab python 如何使用 Mini

沙发
olympic 发表于 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

藤椅
abelus 发表于 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)

板凳
abelus 发表于 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)

报纸
hellojac 发表于 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.

地板
oliyiyi 发表于 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系数。

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

7
peaktang 在职认证  发表于 2023-9-25 12:39:33
怎么样才能显示出全部的结果。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-3 05:36