基于Python第三方库NetworkX,计算Web结构图的HITS得分。示例Web结构图如下:
import networkx as nx #构造Web图 G = nx.DiGraph() G.add_edge('A', 'B') G.add_edge('A', 'C') G.add_edge('B', 'C') G.add_edge('C', 'A') #调用HITS算法 h,a=nx.hits(G) print('authority:',a) print('hub:',h)
authority: {'A': 3.73253690153012e-09, 'B': 0.38196600982440293, 'C': 0.6180339864430602} hub: {'A': 0.6180339873241926, 'B': 0.3819660103689727, 'C': 2.3068346726976927e-09}