Node degree counts a node’s direct connections. Used as a graph feature, it provides a compact representation of connectivity for classification and other network analyses. section 9.3.1 section 10.1.1
Compute and interpret degree features through a small pipeline:
- Count a node’s neighbors to obtain its global or total degree. section 10.1.1
- Split neighbors into meaningful categories when labels are available, such as fraud degree and legitimate degree. section 10.1.1
- Use the resulting scalar or vector as input to a classifier, while validating whether degree alone captures enough structure. section 9.3.1
- Discount highly connected intermediate nodes in path-based features when raw path counts would overrepresent generic hubs. section 10.2.2
Karate-club classification
A NetworkX karate-club graph represents each node with a one-value embedding containing its degree. That simple feature performs poorly in the shown classification results, while adding category-specific neighbor degrees substantially improves them. section 9.3.1
Fraud-network metrics
For each node, compute total degree, fraud degree, and legitimate degree from the is_fraudster attribute. A node with many fraudulent direct neighbors receives a different representation from one with equally many legitimate neighbors. section 10.1.1
Listing 10.3 Computing types of node degrees in a fraud detection network
def compute_degree_metrics(G):
degree_metrics = {} #1
for node in G.nodes():
neighbors = list(G.neighbors(node))
total_degree = len(neighbors) #2
fraud_degree = sum(1 for neighbor in neighbors
if G.nodes[neighbor].get('is_fraudster', False)) #3
legit_degree = total_degree - fraud_degree #4
degree_metrics[node] = {
'total_degree': total_degree,
'fraud_degree': fraud_degree,
'legit_degree': legit_degree
}
return degree_metrics #5
def get_node_degrees(G, node):
metrics = compute_degree_metrics(G)
return metrics.get(node, {
'total_degree': 0,
'fraud_degree': 0,
'legit_degree': 0
}) #6
Inspect the reusable NetworkX-style implementation for calculating total, fraud, and legitimate degrees, including a default result for missing nodes. section 10.1.1



