# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# %matplotlib inline

df1 = pd.read_csv(r'C:\Users\Jalpa\Desktop\Modular-1\Machine-Learning-Models\DATA\Mall_Customers.csv')
df1

df =df1.drop(columns = ['Unnamed: 0'] , axis=1)
df


from sklearn.cluster import KMeans

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

wcss = []
for i in range(1,15):
    kmean = KMeans(n_clusters=i , init='k-means++' , random_state=30)
    kmean.fit(x)
    wcss.append(kmean.inertia_)
    

wcss

plt.plot(range(1,15)  , wcss)

kmean1= KMeans(n_clusters=5 ,init = 'k-means++' , random_state=30)
kmean1.fit_predict(x)

x['cluster number'] = kmean1.fit_predict(x)

x[x['cluster number'] ==3]

x[x['cluster number'] ==1]

55 , 31

kmean1.predict([[69,91]])

# # Minibatch Kmean

from sklearn.cluster import MiniBatchKMeans
minibatch_kmean = MiniBatchKMeans(n_clusters=5)
minibatch_kmean.fit(x)

minibatch_kmean.predict([[55,31 ,4]])

# # DBSCAN

from  sklearn.cluster import DBSCAN

dbscan = DBSCAN(eps=1, min_samples=3)
dbscan.fit(x)

x

dbscan.labels_

len(set(dbscan.labels_))

x['cluster number '] = dbscan.labels_

x

from sklearn import metrics

true_label = x['cluster number']
predicted_label = x['cluster number']
metrics.adjusted_rand_score(true_label,predicted_label)


metrics.adjusted_rand_score(x['cluster number'],dbscan.labels_)

metrics.adjusted_rand_score(true_label,predicted_label)

metrics.jaccard_score(true_label,predicted_label, average='macro')

StarcoderdataJupyterScriptsDedupFiltered