Node2Vec turns graph nodes into fixed-length vectors so their network positions can be used in machine-learning tasks. It is a transductive node-embedding method: embeddings describe nodes already present in the graph, so adding new nodes requires retraining. Its walks can be tuned to emphasize either nearby, similar nodes (homophily) or similar structural roles. section 9.3 section 9.5 section 9.1.1
The algorithm creates training data by starting random walks from every node. Each walk is treated as a sentence: visited nodes are its words. Those sentences are passed to a word2vec skip-gram model, which learns vector representations from nodes that occur near one another in walks. Walk length controls the sentence length. section 9.3.2 section 9.5
Unlike a first-order walk, Node2Vec uses second-order biased walks: the next move considers both the current node and the previous step. Edge weights can also affect traversal probability. This lets the walk behavior be tuned toward graph proximity or structural patterns rather than treating all neighboring moves equally. section 9.3.2 section 9.5
A practical Node2Vec workflow is:
- Project the relevant graph, choosing relationship orientation and any relationship weight to retain. section 9.3.3
- Run Node2Vec with an embedding dimension and walk-bias settings, then write each vector to a node property. section 9.3.3
- Use known labels to train a classifier on the embeddings, then evaluate predictions with a classification report and confusion matrix. section 9.2 section 9.3.6
- Compare configurations by their embedding distances and classification accuracy; also test the effect of removing edge weights. section 9.3.6
Predicting stream language from shared audiences
Represent streams as nodes and shared audience as weighted, undirected relationships. Because streams close in this network are likely to share a language, generate homophily-oriented Node2Vec embeddings, train a random forest on streams with known languages, and predict labels for new streams. An inOutFactor of 0.5 encourages more depth-first walks for this proximity-focused goal. section 9.2 section 9.3.3 section 9.3.6
Listing 9.7 Calculating node2vec embeddings and storing them to the database
data = run_query("""
CALL gds.beta.node2vec.write('twitch',
{embeddingDimension:8, relationshipWeightProperty:'weight',
inOutFactor:0.5, writeProperty:'node2vec'})
""")
This query writes eight-element Node2Vec vectors for the projected stream graph, uses relationship weights, and applies an inOutFactor of 0.5. section 9.3.3


