NETWORK Procedure

Example 2.19 Node Embeddings for Zachary’s Karate Club Data

This example uses Zachary’s Karate Club data (Zachary 1977), which describes social network friendships among 34 members of a karate club at a US university in the 1970s. This is one of the standard publicly available data tables for testing node embedding algorithms. It contains 34 nodes and 78 links. The graph is shown in Figure 246.

Figure 246: Zachary’s Karate Club Graph

Zachary’s Karate Club Graph


You can represent the graph by using the following links data table, mylib.LinkSetIn:

data mylib.LinkSetIn;
   input from to @@;
   datalines;
 0  9   0 10   0 14   0 15   0 16   0 19   0 20   0 21
 0 23   0 24   0 27   0 28   0 29   0 30   0 31   0 32
 0 33   2  1   3  1   3  2   4  1   4  2   4  3   5  1
 6  1   7  1   7  5   7  6   8  1   8  2   8  3   8  4
 9  1   9  3  10  3  11  1  11  5  11  6  12  1  13  1
13  4  14  1  14  2  14  3  14  4  17  6  17  7  18  1
18  2  20  1  20  2  22  1  22  2  26 24  26 25  28  3
28 24  28 25  29  3  30 24  30 27  31  2  31  9  32  1
32 25  32 26  32 29  33  3  33  9  33 15  33 16  33 19
33 21  33 23  33 24  33 30  33 31  33 32
;

The following statements use the EMBED=TRUE option to generate node embeddings for the Zachary’s Karate Club data:

proc network
   links    = mylib.LinkSetIn
   outNodes = mylib.OutNodesEmb;
   nodeSimilarity
      jaccard        = false
      embed          = true
      proximityOrder = first
      nSamples       = 10000000;
run;

The output data table mylib.OutNodesEmb contains the embedding vectors for each node. The first three components of the first five node embedding vectors are shown in Output 2.19.1.

Output 2.19.1: Embedding Vectors Output

nodevec_1vec_2vec_3
0-0.07355-0.001896-0.01625
10.03182-0.075615-0.05424
20.12304-0.038353-0.08011
30.02916-0.0713120.08526
40.049340.0112010.10824


For ease of visualization, it is common practice to collapse the multidimensional embeddings down to two dimensions. You can achieve this by using the TSNE procedure.

The following PROC TSNE statements produce a two-dimensional representation of the node embeddings:

proc tsne
   seed        = 1
   data        = mylib.OutNodesEmb
   nDimensions = 2
   perplexity  = 15
   maxIters    = 8000;
   input         vec_:;
   output
      out      = mylib.OutNodesTsne
      copyvars = (node);
run;

For validation, you can run community detection on the same graph.

The following PROC NETWORK statements produce the community labels that correspond to the karate club data:

proc network
   links    = mylib.LinkSetIn
   nodes    = mylib.OutNodesTsne
   outNodes = mylib.OutNodesComm;
   nodesVar
      vars = (_DIM_1_ _DIM_2_);
   community;
run;

Finally, you can plot the two-dimensional embeddings representation, colored by community label, by using the following PROC TEMPLATE and PROC SGRENDER statements. These statements produce the plot shown in Output 2.19.2.

proc template;
   define statgraph vectorPlot;
   begingraph;
      entrytitle "TSNE Embeddings Colored by Community: Vector";
      layout overlay /
         yaxisopts=(labelFitPolicy=Split)
         y2axisopts=(labelFitPolicy=Split);
         ScatterPlot X=_DIM_1_ Y=_DIM_2_ /
            markerattrs=(symbol=circlefilled size=15)
            datalabel=node
            group=community_1
            name="scatter";
         discretelegend "scatter";
      endlayout;
   endgraph;
   end;
run;

proc sgrender data=mylib.OutNodesComm template=vectorPlot; /* use GTL template */
run;

Output 2.19.2: TSNE Representation of Vector Node Embeddings

TSNE Representation of Vector Node Embeddings


In the plot shown in Output 2.19.2, note that the nodes in a particular community (color) appear to be clustered together in the embedded vector space.

The embeddings that are learned by using vector node similarity are functionally similar to the alternative techniques DeepWalk (Perozzi, Al-Rfou, and Skiena 2014; Perozzi 2014) and Node2Vec (Grover and Leskovec 2016; Grover 2016). Although these alternatives are not currently supported in PROC NETWORK, the results are provided here for comparison. The results that are obtained by DeepWalk for the same graph are shown in Output 2.19.3, and the results that are obtained by Node2Vec for the same graph are show in Output 2.19.4.

Output 2.19.3: TSNE Representation of DeepWalk Node Embeddings

TSNE Representation of DeepWalk Node Embeddings


Output 2.19.4: TSNE Representation of Node2Vec Node Embeddings

TSNE Representation of Node2Vec Node Embeddings


Last updated: August 07, 2026