【发布时间】:2020-04-21 06:28:35
【问题描述】:
我有以下使用networkx 创建的图表。
import networkx as nx
G = nx.Graph()
G.add_nodes_from(["John", "Mary", "Jill", "Todd",
"iPhone5", "Kindle Fire", "Fitbit Flex Wireless", "Harry Potter", "Hobbit"])
G.add_edges_from([
("John", "iPhone5"),
("John", "Kindle Fire"),
("Mary", "iPhone5"),
("Mary", "Kindle Fire"),
("Mary", "Fitbit Flex Wireless"),
("Jill", "iPhone5"),
("Jill", "Kindle Fire"),
("Jill", "Fitbit Flex Wireless"),
("Todd", "Fitbit Flex Wireless"),
("Todd", "Harry Potter"),
("Todd", "Hobbit"),
])
现在,我想执行random walk with restarts 来识别与John 最相似的用户。我在networkx 中搜索了文档,但在networkx 中找不到它的实现。
如果有 random walk with restarts 的 python 库/代码来执行此操作,请告诉我。
如果需要,我很乐意提供更多详细信息。
编辑
如果我现有网络的权重如下所示,我是否仍会按以下方式计算随机游走并重新启动:nx.pagerank_numpy(G, personalization={"John": 1})?
import networkx as nx
G = nx.Graph()
G.add_nodes_from(["John", "Mary", "Jill", "Todd",
"iPhone5", "Kindle Fire", "Fitbit Flex Wireless", "Harry Potter", "Hobbit"])
G.add_weighted_edges_from([
("John", "iPhone5", 0.1),
("John", "Kindle Fire", 0.2),
("Mary", "iPhone5", 0.3),
("Mary", "Kindle Fire", 0.4),
("Mary", "Fitbit Flex Wireless", 0.5),
("Jill", "iPhone5", 0.9),
("Jill", "Kindle Fire", 0.1),
("Jill", "Fitbit Flex Wireless", 0.1),
("Todd", "Fitbit Flex Wireless", 0.1),
("Todd", "Harry Potter", 0.1),
("Todd", "Hobbit", 0.1),
])
【问题讨论】: