image_output_1.png
from sklearn.cluster import KMeans

import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('../input/customer-segmentation-tutorial-in-python/Mall_Customers.csv')

x = df.iloc[:, [3, 4]]

from sklearn.cluster import KMeans
wcss = []
for i in range(1, 11):
    km = KMeans(n_clusters=i, init='k-means++', max_iter=300, n_init=10, random_state=0)
    km.fit(x)
    wcss.append(km.inertia_)
plt.plot(range(1, 11), wcss)
plt.title('The Elbow Method', fontsize=20)
plt.xlabel('No. of Clusters')
plt.ylabel('wcss')
plt.show()