<jupyter_start><jupyter_text>Normalise the dataWithout Normalising, the clusters are mostly segmented based on income due to its high variation.The scale of age is 0 to 60, while salary ranges from 0 to 50K. For example, the difference between the ages of 20 and 70 is significant but numerical difference is only 50. On the other side, salary difference between 1000 and 1100 is only 1000, but the numerical number is very high.Hence we use Normalising technique which will help the numbers to get alligned.It basically normalises all values by subtracting all values from its mean and then dividing it by standard deviation.<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaled_df = scaler.fit_transform(customer_df[['age','income']])
scaled_df[:5]
from sklearn.cluster import KMeans
cluster = KMeans(3, random_state= 42)
cluster.fit(scaled_df)
customer_df['Cluster_id'] = cluster.labels_
customer_df.head(2)
markers = ['+','^','.']
sns.lmplot('age','income',data=customer_df,fit_reg=False,hue = 'Cluster_id',markers = markers,size =6)
customer_df.groupby('Cluster_id')['age','income'].agg({'mean','std'}).reset_index()<jupyter_output><ipython-input-21-827c5d709200>:1: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  customer_df.groupby('Cluster_id')['age','income'].agg({'mean','std'}).reset_index()
{'fraction_non_alphanumeric': 0.1074438202247191, 'fraction_numerical': 0.030196629213483147, 'mean_word_length': 6.916666666666667, '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': '420911', 'license': 'Apache-2.0', 'n_tokens_mistral': 459, 'n_tokens_neox': 414, 'n_words': 146, 'path': 'Clustering - Salary.ipynb', 'repo_name': 'Lokeshrathi/Clustering_algorithm_solution', 'size': '1424'}