How do you go about solving a problem of classifying some data without having any labels associated with the data?
Consider a Social Network Analysis problem. Let’s look at a group of people on social network and get data about-
- Who are the people that are exchanging messages back and forth?
- Who are the group of people posting regularly on certain kind of groups?
Now coming up with an analysis and classifying certain kinds of people together without labeling/naming them as any group- this kind of Machine Learning Classification problem is termed as Unsupervised Learning. K-Means, is by far the most popular and widely used algorithm in the Unsupervised Learning.
How it works?
Let me demonstrate with an example given by Andrew Ng in his Machine Learning Algorithm tutorials. Consider these unlabeled data points-
The first step would be to randomly initialize cluster centroids. In this example, I am taking the number of centroids as 2. But this number can vary as to how many unlabeled groups you want to divide your data into.
The second step is Cluster Assignment step. So, we go through each and every data point and depending upon whether it’s closer to Red or Blue Cluster Centroid, color the data points as Red or Blue.
The third step is the Move Centroid step. This step involves moving each cluster centroid to a position derived by calculating the mean of the corresponding colored data points. This means blue point would be moved to the Mean we get from all the Blue data points and similarly for Red.
Step Second and third would be repeated till the time the Cluster Centroid do not move any further.
What is Cost Function?
In this case, the Cost function is the total sum of the squared distance of every point to its corresponding cluster centroid.
The objective of K-Means id is to minimize the Cost Function.
A Proof of Concept was done to demonstrate the accuracy of this algorithm by supplying training data set to MLLIB library of Apache Spark. Please refer this for setting up Apache Spark on your machine. Marks were collected of the First Semester students from an Engineering Institute.
Java Program to provide marks of students as training data.
Main Class – com.apache.spark.kmeans.App
Executable Jar to run on Apache Spark – /home/prateek/Documents/work/caarmo/Apache-SparkWorkspace/kmeans/target/kmeans.jar
Within Set Sum of Squared Errors shows the Cost Function for the given training data.
Cluster centers shows the two Cluster Centroids derived from the data.
References : https://class.coursera.org/ml-005/lecture