本文介绍了如何在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中编写用于链接预测精度评估的代码?
发布评论