<jupyter_start><jupyter_text>Density Based Clustering and Validation of 3D data<jupyter_code>#Importing libraries
from sklearn.datasets.samples_generator import make_blobs

import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
%matplotlib notebook

import numpy as np
import hdbscan
#Generating sample 3D data 
data, labels = make_blobs(n_samples=100, centers=3, n_features=3)
x,y,z = np.hsplit(data,3)
x = np.concatenate(x,axis=0);y = np.concatenate(y,axis=0);z = np.concatenate(z,axis=0)

#Fig1 - Visualizing sample 3D data
fig = plt.figure( )
plt.style.use('dark_background')
ax = fig.add_subplot(1,1,1, projection = '3d')
ax.grid(False)
ax.scatter (x, y, z, c = 'g', marker='o', s=1, linewidths=2)
ax.set_title('Sample data for clustering')
ax.set_xlabel ('x, axis')
ax.set_ylabel ('y axis')
ax.set_zlabel ('z axis')
plt.show()
plt.close()
#Training HDBSCAN model
model = hdbscan.HDBSCAN(min_cluster_size = 20, gen_min_span_tree = True)
model.fit(data)
print(model)
plt.close()
model.condensed_tree_.plot()
plt.close()
model.condensed_tree_.plot(select_clusters=True)
plt.close()
model.minimum_spanning_tree_.plot(edge_cmap = 'viridis', edge_alpha =0.6, node_size = 80, edge_linewidth =2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13280632411067195, 'fraction_numerical': 0.02292490118577075, 'mean_word_length': 6.9125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '371090', 'license': 'MIT', 'n_tokens_mistral': 517, 'n_tokens_neox': 496, 'n_words': 106, 'path': 'Jupyter notebooks & Docs/3D HDBSCAN Tutorial.ipynb', 'repo_name': 'MonicaSelvaraj/Drosophila-germ-plasm', 'size': '1265'}