<jupyter_start><jupyter_text>Hierarchical Clustering<jupyter_code>import pandas as pd
import numpy as np
from sklearn.preprocessing import normalize
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.cluster.hierarchy import dendrogram, linkage, fcluster
path = 'D:\data science\Wholesale customers data.csv'
df = pd.read_csv(path)
df.head()<jupyter_output><empty_output><jupyter_text>As we can see that the data is not of an even range, applying any algorithm on it will make it biased towards a perticular attribute<jupyter_code>normal = normalize(df)
normal_df = pd.DataFrame(normal, columns = df.columns)
normal_df.head()
mergings_ward = linkage(normal_df, method = 'ward')
dendrogram(mergings_ward,
           leaf_rotation = 90,
           leaf_font_size = 6)
plt.show()<jupyter_output><empty_output><jupyter_text>With complete the height to be used is 1.37 and for ward it is 6<jupyter_code>#Now we have to classify our modeland predict the output
labels = fcluster(mergings_ward, 6, criterion = 'distance')
plt.figure(figsize = (10, 7))
plt.scatter(normal_df['Milk'], normal_df['Fresh'], c = labels)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09466437177280551, 'fraction_numerical': 0.00946643717728055, 'mean_word_length': 6.091463414634147, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '297677', 'license': 'MIT', 'n_tokens_mistral': 411, 'n_tokens_neox': 387, 'n_words': 112, 'path': 'Hierarchical clustering.ipynb', 'repo_name': 'crushnebula7/Unsupervised-learning', 'size': '1162'}