Machine Learning:Algorithms
KMeans Algorithm
Starting from the basics of KMeans first, to
understand KMEANS we need to understand
first what is the meaning of KMeans. The word KMeans, we have two words K and
Means which corresponds to number of clusters and their mean values
respectively.
Goal of the Algorithm: - To calculate the center of each of the given
clusters by taking the mean of all of the points present in each of the cluster.
Steps of this Algorithm: -
1) Start by having a
random number of points according to the number of clusters as their centroids.
2) Now, we have to
assign each point to its nearest cluster by calculating the distance of that
point from all the points present in the various clusters. Like this all points
will be assigned to a particular cluster.
3) Find the new center
of the cluster by taking the mean of all the points in that respective cluster,
and assign that mean to that random point. So, from now each random point will
become the center of each of the cluster.
4) Repeat the above 2
steps until there is no more changes seen in the values of the cluster centers.
Applications: -
1) Used wherever we have
to do clustering,
2) Fraud Detection,
3) Web data clustering,
4) Clustering of various
breeds of various animals,
5) Clustering of persons
living in a particular city,
Code using scikit-learn: -
First, I have created a dataset for the Algorithm,
using numpy, and the code for that is: -
Now, I have implemented
KMeans using sklearn, code for that is: -
Now, here is the
output for that: -
If you want to learn more about AI then give my previous blogs a read.
This blog is written by
and managed by
For more such blogs and updates follow my facebook link:
Comments
Post a Comment