<jupyter_start><jupyter_text>Louvain This notebook illustrates the embedding of a graph through Louvain clustering.<jupyter_code>from IPython.display import SVG
import numpy as np
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.embedding import LouvainEmbedding, BiLouvainEmbedding
from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph<jupyter_output><empty_output><jupyter_text>Graphs<jupyter_code>graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
louvain = LouvainEmbedding()
embedding = louvain.fit_transform(adjacency)
embedding.shape
position = embedding[:, :2]
image = svg_graph(adjacency, position, labels=labels)
SVG(image)<jupyter_output><empty_output><jupyter_text>Digraphs<jupyter_code>graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
louvain = LouvainEmbedding()
embedding = louvain.fit_transform(adjacency)
embedding.shape
position = embedding[:, :2]
image = svg_digraph(adjacency, position, names=names)
SVG(image)<jupyter_output><empty_output><jupyter_text>Bigraphs<jupyter_code>graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
bilouvain = BiLouvainEmbedding(merge_isolated=False)
bilouvain.fit(biadjacency)
embedding_row = bilouvain.embedding_row_
embedding_col = bilouvain.embedding_col_
position_row = embedding_row[:, :2]
position_col = embedding_col[:, :2]
image = svg_bigraph(biadjacency, names_row, names_col, 
                    position_row=position_row, position_col=position_col,
                    color_row='blue', color_col='red')
SVG(image)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09236234458259325, 'fraction_numerical': 0.002368265245707519, 'mean_word_length': 8.135135135135135, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '320410', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 604, 'n_tokens_neox': 577, 'n_words': 101, 'path': 'docs/tutorials/embedding/louvain_embedding.ipynb', 'repo_name': 'abidlabs/scikit-network', 'size': '1689'}