如何在python中编写用于链接预测精度评估的代码?

编程入门 行业动态 更新时间:2024-10-07 12:21:46
本文介绍了如何在python中编写用于链接预测精度评估的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用adamic_adar索引进行链接预测问题.数据集是一个网格网络(具有1000个链接的边列表).我从观察到的数据集中随机选择了80%(800)的边缘.我需要从如下所示的Pred中选择最高的200条预测链接,并计算出精确率.我不知道下一步该怎么做.我该怎么办..帮助!

I am doing a link prediction problem using the adamic_adar index. The dataset is a grid network(edgelist with 1000 links). I randomly selected 80% (800) of the edges from the observed dataset. I need to select the highest 200 predicted links from preds as below and also calculate the precision ratio. I dont know what to do next. How would I do..help!

import numpy as np import networkx as nx G = nx.read_edgelist('Grid.txt', create_using=nx.Graph(), nodetype=int) preds = nx.adamic_adar_index(G); for u, v, p in preds: '(%d, %d) -> %.8f' % (u, v, p) print(u, v, p)

推荐答案

我假设u,v是图形的顶点,p是精度.

I assume u, v to be the vertex of the graph, and p be the precision.

import numpy as np import networkx as nx import random G = nx.read_edgelist('Grid.txt', create_using=nx.Graph(), nodetype=int) preds = nx.adamic_adar_index(G) preds = random.sample(preds, int(len(preds)*0.8)) preds = sorted(preds, key=lambda x: x[2], reverse=True)[:200] ratio = sum([t[2] for t in preds])/len(preds) print(ratio)

更多推荐

如何在python中编写用于链接预测精度评估的代码?

本文发布于:2023-11-28 04:32:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精度   代码   链接   如何在   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!