栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

220602-多维数组的Jaccard指数计算

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

220602-多维数组的Jaccard指数计算

背景:计算两个多维数据的交并商

a = np.arange(0,9).reshape(-1,3)
print(a)

b = np.arange(4,13).reshape(-1,3)
print(b)

c = np.random.rand(4,3)
print(c, 'n')


A = np.concatenate([a,c],axis=0)
B = np.concatenate([b,c],axis=0)

print(A)
print(B)

def jaccard_index_arr(A, B):
    inter = np.array([x for x in set(tuple(x) for x in A) & set(tuple(x) for x in B)])
    union = np.array([x for x in set(tuple(x) for x in A) | set(tuple(x) for x in B)])
    index = len(inter)/len(union)
    print(len(inter), len(union), index)
    return index

jaccard_index_arr(A, B)
import pandas as pd 
from auto_funcs2 import jaccard_array_similarity


df_pre = pd.read_pickle("jaccard.pkl")
num_cat = 10

def get_indicator_jaccard(df_pre, num_cat):
    import pandas as pd 
    import numpy as np
    jas_list = []
    for c in range(num_cat):
        try:
            A = df_pre[df_pre['pse_lab']==c][['red1', 'red2']].to_numpy()
            B = df_pre[df_pre['usp_lab']==c][['red1', 'red2']].to_numpy()
            jas = jaccard_array_similarity(A,B)
            jas_list.append(jas)
            print(jas)
        except:
            jas_list.append(0)
    jas_mean = np.mean(jas_list)
    print(jas_mean)
    return jas_mean
    
std_dif = get_indicator_jaccard(df_pre, num_cat)

  • 参考文献

  • [1] https://stackoverflow.com/questions/8317022/get-intersecting-rows-across-two-2d-numpy-arrays

  • [2] https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html

  • [3] https://leetcode.com/problems/intersection-of-two-arrays/

  • [4] https://scikit-learn.org/0.15/modules/generated/sklearn.metrics.jaccard_similarity_score.html

  • [5] https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.jaccard.html

  • [6] https://www.statology.org/jaccard-similarity-python/

  • [7] https://blog.csdn.net/weixin_42094614/article/details/80117965

  • [8] https://zhuanlan.zhihu.com/p/358736351

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/948164.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号