text_plain_output_1.png
from fcmeans import FCM

from fcmeans import FCM

from sklearn.metrics import silhouette_score

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

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

df.drop('Gender', inplace=True, axis=1)

df.sample(3)

df.isnull().sum()

X_numerics = df[['Age', 'Annual Income (k$)', 'Spending Score (1-100)']]

ax = sns.pairplot(X_numerics[X_numerics.columns])

data = X_numerics.values

import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import silhouette_score
from fcmeans import FCM
min_clusters = 2
max_clusters = 10
silhouette_scores = []
cluster_numbers = []
for n_clusters in range(min_clusters, max_clusters + 1):
    fcm = FCM(n_clusters=n_clusters)
    fcm.fit(data)
    labels = fcm.predict(data)
    silhouette_avg = silhouette_score(data, labels)
    silhouette_scores.append(silhouette_avg)
    cluster_numbers.append(n_clusters)
plt.plot(cluster_numbers, silhouette_scores, marker='o')
plt.xlabel('Number of Clusters')
plt.ylabel('Silhouette Score')
plt.title('Silhouette Score for Different Numbers of Clusters')
plt.show()