0% found this document useful (0 votes)
13 views3 pages

Elbow Method Using Sns

Uploaded by

kaveeshgowda555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Elbow Method Using Sns

Uploaded by

kaveeshgowda555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

In [57]: import pandas as pd

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data=pd.read_csv("C:\\Users\\Liki\\Onedrive\\Documents\\Mall_Customers.csv")
display(data)
data.tail()
data.head()
x=data.iloc[:,[3,4]]
display(x)
sns.scatterplot(x="Annual Income (k$)",y="Spending Score (1-100)",data=data)
from sklearn.cluster import KMeans
cs=[]
for i in range(1,11):
kmeans=KMeans(n_clusters=i,init='k-means++',random_state=42)
kmeans.fit(x)
cs.append(kmeans.inertia_)
plt.plot(range(1,11),cs,marker='o')
plt.title("The Elbow method\n")
plt.xlabel("Number of clusters")
plt.ylabel("cs")


CustomerID Genre Age Annual Income (k$) Spending Score (1-100)

0 1 Male 19 15 39

1 2 Male 21 15 81

2 3 Female 20 16 6

3 4 Female 23 16 77

4 5 Female 31 17 40

... ... ... ... ... ...

195 196 Female 35 120 79

196 197 Female 45 126 28

197 198 Male 32 126 74

198 199 Male 32 137 18

199 200 Male 30 137 83 


In [ ]: ​

You might also like