Node2VecWalk(walkLength:Int = 10, p: Double = 1.0, q: Double = 1.0)

Node2Vec biased random walk on directed, unweighted graph

Node2Vec is used to construct feature vectors to represent vertices or edges in a graph such that classical machine learning algorithms can be applied to the resulting vector representations for network analysis tasks, such as node classification and link prediction. This algorithm implements the Node2Vec biased 2nd-order random walk model to sample neighbors of every vertex in a graph. This random walk model interpolates between breadth-first and depth-first search in the graph in a flexible manner so that local and global structures of the vertex neighborhood can both be captured. In this way, it is capable of supporting different varieties of graphs and analysis tasks well.This implementation is based on Fast-Node2Vec and computes transition probabilities on the fly rather than precomputing all probabilities in advance.


This implementation currently does not support edge weights. This algorithm also only implements the random walk step of Node2Vec. For a full implementation of Node2Vec, the resulting output should be fed into a skip-gram model.1


If the walk reaches a vertex with out-degree 0, it will remain there until walkLength is reached.


walkLength: Int = 10

Lengths of the generated random walks

p: Double = 1.0

bias parameter \(p\)

q: Double = 1.0

bias parameter \(q\)


walk: ArrayBuffer[String]

List of vertices visited by the random walk starting from this vertex


vertex 1

vertex 2

vertex walkLength

name: String

name: String

name: String

Each row of the table corresponds to a single random walk and columns correspond to the vertex at a given step. The algorithm starts one random walk from each vertex in the graph.


node2vec: Scalable Feature Learning for Networks