<jupyter_start><jupyter_text>Disjoint clusters  generate random data<jupyter_code>np.random.seed(5) # random seed for consistency
N = 4
k = 4

cov_mat = np.eye(2)/10

X1 = np.vstack([np.random.multivariate_normal([-1, -1], cov_mat, N),
                np.random.multivariate_normal([-1, +1], cov_mat, N),
                np.random.multivariate_normal([+1, -1], cov_mat, N),
                np.random.multivariate_normal([+1, +1], cov_mat, N)])
cols1 = [0] * N + [1] * N + [2] * N + [3] * N<jupyter_output><empty_output><jupyter_text>plot data with original cluster colors<jupyter_code>fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
ax.scatter(X1[:,0], X1[:,1], s=10, c='grey', alpha=1, linewidth=0)
for i in xrange(X1.shape[0]):
    ax.text(X1[i, 0], X1[i, 1], '%s' % i)
plt.show()<jupyter_output><empty_output><jupyter_text>Dendrogram for Single Link<jupyter_code>Z1_single = linkage(X1, method='single', metric='euclidean')
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
dendrogram(Z1_single, leaf_rotation=90, leaf_font_size=8, ax=ax)
ax.set_title('Single link, Euclidean distances')
plt.show()<jupyter_output><empty_output><jupyter_text>Dendrogram for Average Link<jupyter_code>Z1_average = linkage(X1, method='average', metric='euclidean')
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
dendrogram(Z1_average, leaf_rotation=90, leaf_font_size=8, ax=ax)
ax.set_title('Average link, Euclidean distances')
plt.show()<jupyter_output><empty_output><jupyter_text>Example with two concentric rings<jupyter_code>np.random.seed(1) # random seed for consistency
N = 200

theta = np.random.uniform(size=(2*N, 1)) * 2 * np.pi
r     = np.vstack([np.random.uniform(low=0.8, high=1.2, size=(N, 1)),
                   np.random.uniform(low=1.8, high=2.2, size=(N, 1))])

x = np.multiply(r, np.cos(theta))
y = np.multiply(r, np.sin(theta))
X2 = np.hstack([x, y])
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
ax.scatter(X2[:,0], X2[:,1], s=10, c='grey', alpha=1, linewidth=0)
#for i in xrange(X2.shape[0]):
#    ax.text(X2[i, 0], X2[i, 1], '%s' % i)
plt.show()<jupyter_output><empty_output><jupyter_text>performing K-means with K=2<jupyter_code>Z2_single = linkage(X2, method='single', metric='euclidean')
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
dendrogram(Z2_single, leaf_rotation=90, leaf_font_size=8, ax=ax)
ax.set_title('Single link, Euclidean distances')
plt.show()<jupyter_output><empty_output><jupyter_text>Scatter plot of the clustering results<jupyter_code>Z2_average = linkage(X2, method='average', metric='euclidean')
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
dendrogram(Z2_average, leaf_rotation=90, leaf_font_size=8, ax=ax)
ax.set_title('Average link, Euclidean distances')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1809761311008194, 'fraction_numerical': 0.04310651941574635, 'mean_word_length': 6.255813953488372, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '448258', 'license': 'MIT', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1166, 'n_words': 198, 'path': 'jupyter_notebooks/Hierarchical clustering example.ipynb', 'repo_name': 'eladnoor/sysbio2016', 'size': '2807'}