Katz centrality

This notebook illustrates the ranking of the nodes of a graph by Katz centrality, a weighted average of number of paths of different lengths to each node.

[1]:
from IPython.display import SVG
[2]:
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.ranking import Katz
from sknetwork.visualization import visualize_graph, visualize_bigraph

Graphs

[3]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[4]:
katz = Katz()
scores = katz.fit_predict(adjacency)
[5]:
image = visualize_graph(adjacency, position, scores=scores)
SVG(image)
[5]:
../../_images/tutorials_ranking_katz_7_0.svg

Directed graphs

[6]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
[7]:
katz = Katz()
scores = katz.fit_predict(adjacency)
[8]:
image = visualize_graph(adjacency, position, scores=scores, names=names)
SVG(image)
[8]:
../../_images/tutorials_ranking_katz_11_0.svg

Bipartite graphs

[9]:
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[10]:
katz = Katz()
katz.fit(biadjacency)
scores_row = katz.scores_row_
scores_col = katz.scores_col_
[11]:
image = visualize_bigraph(biadjacency, names_row, names_col, scores_row=scores_row, scores_col=scores_col)
SVG(image)

[11]:
../../_images/tutorials_ranking_katz_15_0.svg