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

import pandas as pd

data=pd.read_csv('xclara.csv')

data.head()

import numpy as np

c1=data['V1'].values

c2=data['V2'].values

from sklearn.cluster import KMeans

range_cluster = [1,2,3,5,7,10,15]

sse={}
# dictionary

for n_clusters in range_cluster:
    kmeans=KMeans(n_clusters=n_clusters)
    kmeans_label=kmeans.fit(data)
    sse[n_clusters]=kmeans_label.inertia_
    #inertia is the score function for Kmeans
    #inertia finds the fitting 

from matplotlib import pyplot as plt
#plt.figure()
plt.plot(list(sse.keys()),list(sse.values()))
plt.xlabel('Number of Cluster')
plt.ylabel('cost')
plt.show()
#Prefered K is seen to be as 3

plt.scatter(c1,c2,c='yellow') #represents the enrties as a cluster 

kmeans=KMeans(n_clusters=3)# any numnber can be putt here <the number will make the amount of clusters>
kmeans_label=kmeans.fit_predict(data)#helps to make the graph

plt.scatter(c1,c2,c=kmeans_label)# are the 3 clusters which are to be plotted

centroids=kmeans.cluster_centers_ #center points of the clusters in the graph

centroids

##### make a KNN code on your own using any Dataset




StarcoderdataJupyterScriptsDedupFiltered