我一直在努力把我的工作图表聚在一起。
边权值是两个节点(作业)之间的转换数。
我一直在阅读我的代码,我的代码是基于本文:https://hal.archives-ouvertes.fr/hal-01887680/document
代码:
G = nx.DiGraph() #Full transitions graph
G.add_weighted_edges_from(list(transitions_df.itertuples(index=False, name=None)))
H = nx.subgraph(G, list(df.query("sub_family_desc == 'ClientSupport' | sub_family_desc == 'Consulting' ").code.unique())) #Gruph with only two subfamily_jobs(clusters)
pos = nx.kamada_kawai_layout(H)
weights = nx.get_edge_attributes(H, "weight")
a = nx.spectral_graph_forge(H, 0.7)
adj_mat = nx.to_numpy_matrix(a)
sc = SpectralClustering(2, affinity='precomputed', n_init=100,assign_labels="kmeans",random_state=np.random.seed(1234))
sc.fit(adj_mat)我也尝试添加随机游动,但是我失败了,无法将随机游走传递到SKlean光谱集群
from stellargraph import StellarGraph
#converting it to stellar graph format so we can leverage biased random walk from this library
sg_graph = StellarGraph.from_networkx(H)
print(sg_graph.info())
from stellargraph.data import BiasedRandomWalk
from gensim.models import Word2Vec
#from each singular node/job we generate 40 biased (weight-biased) random walks with a max length of 10
rw = BiasedRandomWalk(sg_graph)
#40 sequences per node
weighted_walks = rw.run(nodes=sg_graph.nodes(),length=10, n=100, p=5, q=0.05, weighted=True, seed=1234)
print("Number of random walks: {}".format(len(weighted_walks)))我应该在模型中添加random_walk吗?我怎么能做到呢?
发布于 2022-07-23 22:28:46
使用卢万社区探测。
https://stackoverflow.com/questions/73057909
复制相似问题