Scikit-network-12:LinkPredict

LinkPredict

使用一阶方法

from numpy import argsort

from sknetwork.classification import accuracy_score
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.linkpred import JaccardIndex, AdamicAdar, is_edge, whitened_sigmoid

Adamic-Adar

根据两个节点之间的共享链接的数量,该度量是在2003年引入的,以预测网络中缺少的链接。

在这里插入图片描述

adjacency = karate_club()
aa = AdamicAdar()
aa.fit(adjacency)

edges = [(0, 5), (4, 7), (15, 23), (17, 30)]
y_true = is_edge(adjacency, edges)
y_true
# [ True, False, False, False]

scores = aa.predict(edges)
y_pred = whitened_sigmoid(scores) > 0.75
accuracy_score(y_true, y_pred)
# 1.0

有向图

graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
names

picasso = 0

aa.fit(adjacency)

scores = aa.predict(picasso)
scores
#[1.24266982, 0.62133491, 0.        , 0.        , 0.        , 0.        , 0.        , 0.62133491, 0.62133491, 0.        , 0.62133491, 1.24266982, 0.62133491, 0.        ]

names[argsort(-scores)]
# ['Pablo Picasso', 'Paul Cezanne', 'Claude Monet', 'Edgar Degas', 'Vincent van Gogh', 'Henri Matisse', 'Pierre-Auguste Renoir', 'Michel Angelo', 'Edouard Manet', 'Peter Paul Rubens', 'Rembrandt', 'Gustav Klimt', 'Leonardo da Vinci', 'Egon Schiele']

二部图

graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names = graph.names
names

inception = 0
aa.fit(biadjacency)
scores = aa.predict(inception)
scores
names[argsort(-scores)]
['Inception', 'The Dark Knight Rises', 'The Great Gatsby',
       'Aviator', 'Midnight In Paris', 'The Big Short', 'Drive',
       'La La Land', 'Crazy Stupid Love', 'Vice',
       'The Grand Budapest Hotel', '007 Spectre', 'Inglourious Basterds',
       'Murder on the Orient Express', 'Fantastic Beasts 2']

JaccardIndex

它是由通过邻居总数归一化的普通邻居数量来计算的。它用于测量两个有限样品集之间的相似性,并定义为交点的大小除以样品集的结合大小。

在这里插入图片描述

graph = karate_club(metadata=True)
adjacency = graph.adjacency

ji = JaccardIndex()
ji.fit(adjacency)

edges = [(0, 5), (4, 7), (15, 23), (17, 30)]
y_true = is_edge(adjacency, edges)
y_true

scores = ji.predict(edges)
y_pred = whitened_sigmoid(scores) > 0.75
y_pred

accuracy_score(y_true, y_pred)
# 0.5

有向图

graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
names

picasso = 0
ji.fit(adjacency)
scores = ji.predict(picasso)
scores
names[argsort(-scores)]
array(['Pablo Picasso', 'Paul Cezanne', 'Claude Monet',
       'Pierre-Auguste Renoir', 'Henri Matisse', 'Edgar Degas',
       'Vincent van Gogh', 'Michel Angelo', 'Edouard Manet',
       'Peter Paul Rubens', 'Rembrandt', 'Gustav Klimt',
       'Leonardo da Vinci', 'Egon Schiele'], dtype='<U21')

二部图

graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names = graph.names
names

inception = 0

ji.fit(biadjacency)

scores = ji.predict(inception)
scores

names[argsort(-scores)]
array(['Inception', 'The Dark Knight Rises', 'The Great Gatsby',
       'Aviator', 'Midnight In Paris', 'The Big Short', 'Drive',
       'La La Land', 'Crazy Stupid Love', 'Vice',
       'The Grand Budapest Hotel', '007 Spectre', 'Inglourious Basterds',
       'Murder on the Orient Express', 'Fantastic Beasts 2'], dtype='<U28')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

uncle_ll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值