easygraph.functions.graph_embedding.node2vec module#
- easygraph.functions.graph_embedding.node2vec.node2vec(G, dimensions=128, walk_length=80, num_walks=10, p=1.0, q=1.0, weight_key=None, workers=None, **skip_gram_params)[source]#
Graph embedding via Node2Vec.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph) –
dimensions (int) – Embedding dimensions, optional(default: 128)
walk_length (int) – Number of nodes in each walk, optional(default: 80)
num_walks (int) – Number of walks per node, optional(default: 10)
p (float) – The return hyper parameter, optional(default: 1.0)
q (float) – The input parameter, optional(default: 1.0)
weight_key (string or None (default: None)) – On weighted graphs, this is the key for the weight attribute
workers (int or None, optional(default : None)) – The number of workers generating random walks (default: None). None if not using only one worker.
skip_gram_params (dict) – Parameters for gensim.models.Word2Vec - do not supply ‘size’, it is taken from the ‘dimensions’ parameter
- Returns:
embedding_vector (dict) – The embedding vector of each node
most_similar_nodes_of_node (dict) – The most similar nodes of each node and its similarity
Examples
>>> node2vec(G, ... dimensions=128, # The graph embedding dimensions. ... walk_length=80, # Walk length of each random walks. ... num_walks=10, # Number of random walks. ... p=1.0, # The `p` possibility in random walk in [Rcb3fa857cc7d-1]_ ... q=1.0, # The `q` possibility in random walk in [Rcb3fa857cc7d-1]_ ... weight_key='weight', ... skip_gram_params=dict( # The skip_gram parameters in Python package gensim. ... window=10, ... min_count=1, ... batch_words=4 ... ))
References