Code for Clustering in R using Iris dataset

> View(iris) To know the optimal no of clusters, using hierarchical clustering methodology: > d=dist(scale(iris[,-5])) > h=hclust(d,method=’ward.D’) > plot(h,hang=-1) > k=kmeans(iris[,-5],3) > rect.hclust(h,h=35,border=”blue”) > k Following dendrogram appeared: Selecting 3 to be most optimal, applying k-means to get the centers for these 3 clusters: > k=kmeans(iris[,-5],3,nstart=20) By giving nstart=20, we are fixing the starting point[…]

How k-means clustering works?

K-means is one of the simplest unsupervised learning algorithms that solve the well-known clustering problem. Algorithm Steps: Step 1: First decide the no of clusters (let suppose k clusters we want to create) Step 2: Randomly assign centres to these k clusters Step 3: Calculate the distance of remaining data points with these k clusters[…]