K Means Cluster Algorithm

 K Means Cluster 

Its a distance based algorithm.The k-means algorithm is a clustering algorithm. That means that you have a bunch of points in some space, and you want to guess what groups they seem to be in. 


K-Means cluster in Python :


First of all import necessary library and read the csv file using panda library


Lets visualize data 


 
Now we build the KMeans  cluster


Now we find the center of group 


You can clearly saw that center is not perfectly fit in group because we didn't performing scaling on over data set. so first we do the scaling on over data set.


Now again we build KMeans cluster model



Now we again find center of our data groups


Now question is How we know the value of K ? 

We can find the value of K using elbow method. In this method we plot the data and where you find the major difference in graph that point is your value of K.

You can download data set by click here.










Comments

Popular posts from this blog

Multivariate logistic regression in Python

Decision tree for titanic dataset in Python