liveBook · Manning

PageRank

As explained in Knowledge Graphs and LLMs in Action

PageRank is a graph-ranking algorithm that estimates the importance of nodes from the structure and importance of incoming links.

PageRank estimates node importance from incoming connections, weighting both their quantity and the importance of the nodes supplying them. It supports graph exploration, influence analysis, and fraud detection. section 10.1.7 section 6.2

A practical PageRank workflow distinguishes two views:

  • Compute base PageRank with all connections treated equally to estimate general network importance. section 10.1.7
  • Compute fraud-weighted PageRank by emphasizing known fraudulent nodes, then compare scores to identify nodes warranting investigation. section 10.1.7

Fraud-network comparison

Node A has the highest base PageRank at 0.108, while node D leads fraud-weighted PageRank at 0.168; the divergence reveals stronger links to fraudulent activity than overall network position suggests. section 10.1.7

Listing 10.9 Computing PageRank variations for fraud detection
import networkx as nx
import numpy as np

def compute_pagerank_metrics(G, fraud_weight=2.0, damping_factor=0.85):
    pagerank_metrics = {}   #1

    base_pagerank = nx.pagerank(
        G,
        alpha=damping_factor,
        personalization=None,
        weight=None
    )   #2

    fraud_personalization = {}
    for node in G.nodes():   #3
        if G.nodes[node].get('is_fraudster', False):
            fraud_personalization[node] = fraud_weight
        else:
            fraud_personalization[node] = 1.0 

    fraud_pagerank = nx.pagerank(
        G,
        alpha=damping_factor,
        personalization=fraud_personalization,
        weight=None
    )  #4

    for node in G.nodes():
        pagerank_metrics[node] = {
            'pagerank_base': round(base_pagerank[node], 3),
            'pagerank_fraud': round(fraud_pagerank[node], 3)
        }   #5

    return pagerank_metrics   #6


def get_node_pagerank(G, node):
    metrics = compute_pagerank_metrics(G)
    return metrics.get(node, {
        'pagerank_base': 0.0,
        'pagerank_fraud': 0.0
    })   #7

Inspect the NetworkX implementation for damping, personalization, fraud weighting, and per-node metric output. section 10.1.7

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Defines incoming-link importance and demonstrates base and personalized computation, without deriving the algorithm mathematically.
Examples
Uses scientist influence networks, cyclotron research, and a fraud graph comparing nodes A and D.
What it assumes
Assumes graph nodes and connections, while distinguishing general importance from importance conditioned on fraudulent nodes.
What you can do after
Diagnose network importance and fraud-related connections by computing comparable PageRank variants with NetworkX.
How it connects
Connects graph analytics with centrality measures, knowledge graphs, influence networks, and fraud detection.

Also explained in

Compare how 3 books explain PageRank →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.