image_output_1.png
from sklearn.cluster import KMeans

from sklearn.metrics import silhouette_score

import pandas as pd

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

df.isna().sum()

df_copy = df.copy()

df1 = df.drop(['CustomerID', 'Gender'], axis=1)
df1

model = KMeans(n_clusters=4, max_iter=1000)
model.fit(df1)

model.predict([[31, 17, 40]])

from sklearn.metrics import silhouette_score
score = silhouette_score(df1, model.labels_)
score