<jupyter_start><jupyter_text>The elbow is is peacefully resting on 3, this means that the right number of clusters to use is 3.<jupyter_code>#Applying k-means to the dataset with the right number of clusters
kmeans = KMeans(n_clusters= 3, init = 'k-means++', max_iter = 300, n_init = 11, random_state = 0)
y_kmeans = kmeans.fit_predict(X)
y_kmeans
#Visualising the clusters
plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 100, c = 'green', label = 'Medium Income Applicants')
plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Low Income Applicants')
plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 100, c = 'red', label = 'High Income Applicants')
plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 200, c = 'yellow', marker ='*', label = 'Centroids')
plt.title('Clusters Of Loan Applicants')
plt.xlabel('Annual Income')
plt.ylabel('Loan Amount (In Thousands)')
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1606425702811245, 'fraction_numerical': 0.035140562248995984, 'mean_word_length': 5.559210526315789, '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': '176882', 'license': 'MIT', 'n_tokens_mistral': 442, 'n_tokens_neox': 373, 'n_words': 112, 'path': '6. K means clustering/K Means Clustering.ipynb', 'repo_name': 'bbp-earthling/Machine-Learning-With-Python-Scikit-Learn', 'size': '996'}