日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

snap-社交网络分析

發(fā)布時間:2024/8/1 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 snap-社交网络分析 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Snap簡介

Stanford Network Analysis Platform (SNAP) is a general purpose network analysis and graph mining library. It is written in C++ and easily scales to massive networks with hundreds of millions of nodes, and billions of edges. It efficiently manipulates large graphs, calculates structural properties, generates regular and random graphs, and supports attributes on nodes and edges.


安裝方法
snap官網(wǎng)地址
1.從上面地址下載python版本壓縮包
2.解壓得到本地目錄下 C:\Users\Joker\snap
3.按進(jìn)入cmd,cd進(jìn)入該目錄,運(yùn)行 python setup.py install。
linux系統(tǒng)下也是一樣的方法。

注意:snap只支持python2.7版本。windows系統(tǒng)也需要64位系統(tǒng)。


文檔和數(shù)據(jù)
snap相關(guān)文檔說明
文檔中包括了一些基本的數(shù)據(jù)類型。還包括了一些比較容易用到的功能的代碼說明:輸出網(wǎng)絡(luò)的基本信息,可視化網(wǎng)絡(luò),度分布圖,各種網(wǎng)絡(luò)分析的功能通常一句代碼就解決了。

社交網(wǎng)絡(luò)數(shù)據(jù)
snap上收集了一些社交網(wǎng)絡(luò)數(shù)據(jù),并且免費(fèi)的分享給大家使用,免去了大家自己從網(wǎng)上爬數(shù)據(jù)的麻煩。業(yè)界良心啊。


連接預(yù)測

from __future__ import divisionimport snap import mathG=snap.LoadEdgeList(snap.PUNGraph,'predict_delete.txt',0,1) d_common={} d_jaccard={} d_adamic={}for N1 in G.Nodes():#print node_listfor N2 in G.Nodes():if((int(N1.GetId())<int(N2.GetId()))and not((N1.GetId()==N2.GetId())or (N1.IsNbrNId(N2.GetId())))):node_list_all=set([])value_adamic=0for Id in N1.GetOutEdges():#save the neighborsnode_list_all.add(Id)#sage the same neighbors of n1 and n2node_list_same=set([])for Id in N2.GetOutEdges():#save the all neighbors of n1 and n2if(Id in node_list_all):node_list_same.add(Id)node_list_n=set([])for N_n in G.GetNI(Id).GetOutEdges():#print N_nnode_list_n.add(N_n)if(len(node_list_n)>0):value_adamic=value_adamic+1/(math.log(len(node_list_n)))else:value_adamic=value_adamic+1node_list_all.add(Id)#if (len(node_list_same)>0):#print node_list_all,node_list_same key=str(N1.GetId())+'-'+str(N2.GetId())value_common=len(node_list_same)value_jaccard=len(node_list_same)/len(node_list_all)d_common[key]=int(value_common)d_jaccard[key]=int(value_jaccard)d_adamic[key]=int(value_adamic)s_common=sorted(d_common.items(),key=lambda item:item[1],reverse=True) s_jaccard=sorted(d_jaccard.items(),key=lambda item:item[1],reverse=True) s_adamic=sorted(d_adamic.items(),key=lambda item:item[1],reverse=True)sample=set([]) with open ('predict_d.txt','r') as f:for line in f.readlines():data=line.strip().split()ids=str(data[0])+'-'+str(data[1])sample.add(ids) count_common=0 count_jaccard=0 count_adamic=0 num=500 #common neighbors with open ('predict_common.txt','w') as f:for i in range(0,num):f.write(str(s_common[i][0])+'\n')if(str(s_common[i][0]) in sample):count_common=count_common+1precise=count_common/numf.write('precise='+str(precise)) #jaccard with open ('predict_jaccard.txt','w') as f:for i in range(0,num):f.write(str(s_jaccard[i][0])+'\n')if(str(s_jaccard[i][0]) in sample):count_jaccard=count_jaccard+1precise=count_jaccard/numf.write('precise='+str(precise)) #adamic with open ('predict_adamic.txt','w') as f:for i in range(0,num):f.write(str(s_adamic[i][0])+'\n')if(str(s_adamic[i][0]) in sample):count_adamic=count_adamic+1precise=count_adamic/numf.write('precise='+str(precise))

通過三個方法計算每兩對節(jié)點(diǎn)的score值。排序,排序top-n的為新出現(xiàn)的連接。
最終比較三個預(yù)測方法,adamic方法的準(zhǔn)確率最高。
common:兩個節(jié)點(diǎn)共同的鄰居的數(shù)量
jaccard:兩個節(jié)點(diǎn)共同鄰居的鄰居的數(shù)量/兩個節(jié)點(diǎn)總鄰居的數(shù)量
adamic:對兩個節(jié)點(diǎn)共同鄰居最加一個權(quán)重w,若某個共同鄰居的鄰居數(shù)非常高,那這個權(quán)重w就可以很小。

總結(jié)

以上是生活随笔為你收集整理的snap-社交网络分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。