<jupyter_start><jupyter_text>Example for SOMClustering<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs

# --- for running the script without pip
import sys
sys.path.append("../")
# ---

import susi
from susi.SOMPlots import plot_nbh_dist_weight_matrix, plot_umatrix<jupyter_output><empty_output><jupyter_text>Get data<jupyter_code>X, y = make_blobs(n_samples=100, n_features=2, centers=3)
plt.scatter([x[0] for x in X], [x[1] for x in X], c=y)
plt.show()<jupyter_output><empty_output><jupyter_text>Classify and plot<jupyter_code>som = susi.SOMClustering(
    n_rows=30,
    n_columns=30
)
som.fit(X)
print("SOM fitted!")<jupyter_output>SOM fitted!<jupyter_text>Plot u-Matrix<jupyter_code>u_matrix = som.get_u_matrix()
plot_umatrix(u_matrix, 30, 30)
plt.show()<jupyter_output><empty_output><jupyter_text>Plot clusters<jupyter_code>clusters = som.get_clusters(X)
plt.scatter(x=[c[1] for c in clusters], y=[c[0] for c in clusters], c=y, alpha=0.2)
plt.gca().invert_yaxis()
plt.show()<jupyter_output><empty_output><jupyter_text>Plot neighborhood distance matrix<jupyter_code>plot_nbh_dist_weight_matrix(som)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.015833333333333335, 'mean_word_length': 8.310077519379846, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '346982', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 514, 'n_tokens_neox': 491, 'n_words': 82, 'path': 'examples/SOMClustering.ipynb', 'repo_name': 'KIT-IPF/susi', 'size': '1200'}