You are on page 1of 8

Task 6

Clustering
Clustering
1. Import the Libraries: numpy, pandas,
matplotlib.pyplot
2. Import the dataset provided using pandas
3. Create a dataframe by selecting only two columns
from the existing dataset: Annual Income and
spending score
4. Plot a scatter plot
5. Use Elbow Method to find the
Number of Clusters
• Select the number of clusters (k) of your choice
(>10)
• Apply K-Means algorithm and form the clusters for
different values of k
• For each value k calculate the within cluster sum of
squares(WCSS)
• Plot the curve according to the number of clusters
from sklearn.cluster import Kmeans
sse =[]
for i in range (1,20):
kmeans = KMeans(n_clusters = i)
kmeans.fit(data)
sse.append(kmeans.inertia_)
Elbow Method
Display the centroids
kmeans.cluster_centers_

You might also like