Unsupervised Machine Learning

Harinath Selvaraj
coding&stuff
Published in
3 min readOct 4, 2018

In case you have not read the basis of machine learning, please read the below article, or else you are good to skip.

Unsupervised learning a supervised learning algorithm draws inferences from data which does not have labels.

Let’s look at the below example —

There are students who do not require any external training and they can learn by themselves. This is the concept of unsupervised learning.

An example of unsupervised learning is clustering. There are many clustering techniques such as

K-means clustering

Hierarchical clustering

Fuzzy C Means clustering

The concept of clustering is simple, there should be high-intra cluster similarity and low inter cluster similarity.

K- Means Clustering with an Example

Now we’ll go ahead and implement the K-means clustering algorithm on top of the iris dataset.

let’s have a glance at the iris dataset -

View(iris)

The iris dataset comprises of 5 columns. Before we build the k-means clustering algorithm on top of this dataset, we need to remove the 5th column because the K-Means Clustering can be applied only on top of the numerical values.

Therefore, we’ll be selecting the first 4 columns from this data set and we’ll store it in iris_k object.

iris_k <- iris[1:4]

Now, we see that the 5th column has been deleted and we just have the first four columns.

View(iris_k)

We also need to convert this data frame into a matrix. We’ll use as.matrix function and convert this data frame into a matrix and store the result back into the iris_k object.

as.matrix(iris_k) -> iris_k

It’s finally time to use the K-means function to divide our data set into clusters. This takes in two parameters — 1st is the data set and next is the number of clusters it is divided into. We are taking iris_k data set and dividing this entire data set into three clusters.

kmeans(iris_k,3) -> iris_cluster

You will see that 150 observations have been divided into three clusters.

We’ll bind the clustering vector with the original data set to have a better analysis. Let’s have a glance at this clustered data object so you have binded the clustering vector object with the original data set.

cbind(iris,iris_cluster$cluster) -> clustured_Data

If we have a closer look at this data set, you will understand that the first 50 observations of this data set (or) all of the setosa species of the iris flower have been grouped into the third cluster and the rest of the hundred observations i.e.) virginica and versicolor have been grouped in cluster no.1 and cluster no.2.

We have implemented the k-means algorithm on top of the iris data set 😃

Reinforcement Learning

Reinforcement learning is a type of machine learning algorithm, with the machine or agent in an environment, learns ideal behaviour in order to maximise its performance.

An simple reward feedback is required for the agent to learn its behaviour. This is known as Reinforcement Signal.

Let’s take pac-man for example : As long as pac-man keeps eating food, it earns points but when it crashes against a monster, it loses its life. This is how pac-man learns that it needs to eat more food and avoid monsters so as to improve its performance.

Some real-world applications of reinforcement learning include Google self-driving car, the manufacturing robots used in the industry & autonomous flying helicopters used in the military.

Thanks for reading 😃!

--

--